RequiredFieldValidator
The RequiredFieldValidator control check the value is null("") or empty before the user submit the values.The control fails validation if the value it contains does not change from its initial value when validation is performed. If all the fields in the page are valid, the page is valid.
Required Field Validator Propertites
ControlToValidate: Gets or sets the input control to validate.
ErrorMessage: Gets or sets the text for the error message displayed in a ValidationSummary control when validation fails.
ValidationGroup: Gets or sets the name of the validation group to which this validation control belongs.
Text: Gets or sets the text displayed in the validation control when validation fails.
The RequiredFieldValidator control check the value is null("") or empty before the user submit the values.The control fails validation if the value it contains does not change from its initial value when validation is performed. If all the fields in the page are valid, the page is valid.
Required Field Validator Propertites
ControlToValidate: Gets or sets the input control to validate.
ErrorMessage: Gets or sets the text for the error message displayed in a ValidationSummary control when validation fails.
ValidationGroup: Gets or sets the name of the validation group to which this validation control belongs.
Text: Gets or sets the text displayed in the validation control when validation fails.
Example:
<table > <tr> <td > Name</td> <td > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> <td> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please fill the name" ValidationGroup="validate">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td > </td> <td > <asp:Button ID="Button1" runat="server" Text="Submit" ValidationGroup="validate" /> </td> <td> </td> </tr> </table>
Right click the required field validator and select PROPERTIES
And change required field validator PROPERTIES as shown in the image
Right click the button and select PROPERTIES and set validationgroup : validate
Run the Example
Output:
Note: Error message properties work when we use validation summary control.
0 comments:
Post a Comment