ErrorProvider Control in VB.NET
ErrorProvider Control is used to set Error Message for particular control on the Form.
You can also also get Error Message associated with particular control on the form using ErrorProvider Control.
Properties of ErrorProvider Control
Various Properties of ErrorProvider Control are:
| Property Name | Description |
| Name | It is used to specify name of ErrorProvider Control. |
| BlinkRate | It is used to specify rate in milisecond at which error icon blinks. |
| BlinkStyle | It is used to specify Blink Style for Error Icon. It can be: AlwaysBlink, NeverBlink, BlinkIfDifferentError |
| Icon | It is used to specify ICON to be displayed near to the control when error is set for that control. |
Methods of ErrorProvider Control
Various Methods of ErrorProvider Control are:
| Method Name | Description |
| SetError | It is used to set error message for particular control. Syntax: ErrorProvider1.SetError(ControlName,"ErrorMessage") |
| GetError | It is used to retrieve current error message of particular control. Syntax: ErrorProvider1.GetError(ControlName) |
| Clear | It is used to clear all the settings of ErrorProvider Control. Syntax: ErrorProvider1.Clear() |
Example of ErrorProvider Control in VB.NET
Design a From as shown below:
Now Set Properties of various control as below:
| Control Name | Property Name | Value |
| Form1 | Text | ErrorProvider Control Demo |
| Label1 | Text | Enter Your Name |
| Textbox1 | Name | txtName |
| Button1 | Name | btnSubmit |
| Text | Submit | |
| Label2 | Text | Your Name Is: |
| Label3 | Name | lblName |
| Text | Name | |
| ErrorProvider1 | Name | ErrorProvider1 |
| BlinkStyle | AlwaysBlink |
Now Double click on Submit Button and write following code in Click event.
ErrorProvider1.Clear()
If txtName.Text = "" Then
ErrorProvider1.SetError(txtName, "Please Enter Name")
txtName.Focus()
lblName.Text = ErrorProvider1.GetError(txtName)
Else
lblName.Text = txtName.Text
End If