When would you use ErrorProvider control?

ErrorProvider control is used in Windows Forms application. It is like Validation Control for ASP.NET pages. ErrorProvider control is used to provide validations in Windows forms and display user friendly messages to the user if the validation fails.
E.g.If we went to validate the textBox1 should be empty, then we can validate as below
You need to place the errorprovide control on the form

private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
ValidateName();
}
private bool ValidateName()
{
bool bStatus = true;
if (textBox1.Text == "")
{
errorProvider1.SetError (textBox1,"Please enter your Name");
bStatus = false;
}
else
{
errorProvider1.SetError (textBox1,"");
return bStatus;
}
}

it check the textBox1 is empty . If it is empty, then a message Please enter your name is displayed.

it check the textBox1 is empty . If it is empty, then a message Please enter your name is displayed.
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*