VB.net Tutorials with Examples

VB.Net Projects

VB.Net Project 1

adplus-dvertising
Required FieldValidator control
Previous Home Next

It is used to verify if a value has been provided for a control or not.As the name suggest, this validation control make sure that control mention in Control ToValidate cannot be empty.

Common properties for all the validation controls:

PropertiesDescription
ControlToValidate Specifies the name of the control which has to be validated.
ErrorMessage Specifies the error message to be displayed if the validation control returns ‘false’.

Note:If customization or if validation controls has to be extended then the “Text” property for the validation controls should be set. If more than one validation control validates a standard control then it is mandatory that the “Display” property for all the validation controls should be set as “Dynamic”. Other than the ‘RequiredFieldValidator’ control, remaining validation controls will not validate the controls if the value for the control is empty.

.aspx Code

< asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
ControlToValidate="TextBox1" ErrorMessage="* Blank are not allowed" 
SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>

Output:

Previous Home Next