Validation controls are added on the page to enable user input validation. Validation Controls work by referencing input control such as Textboxes, RadioButtons, DropDownList etc. to a validator. When a user enters all the details in a form and clicks on the submit button, the validators associated with each input control responds by validating values that were entered. If the input validation fails, the page will be returned.
Validators can also be enabled or disabled by setting them in the properties. These validators can be grouped together to enable or disable them in groups.
There are a few types of validation controls that can be applied on the web.
RequiredFieldValidator
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="RequiredFieldValidator">
<\asp:RequiredFieldValidator>
Simple and very useful validator that is used to validate and ensure input controls are entered with some value and prevents any attempt to leave the controls empty.
Example
<asp:RequiredFieldValidator ID="RequiredValidationCity"
runat="server"
ErrorMessage="Please enter a
City"
ForeColor="Red"
ControlToValidate="txtState"
SetFocusOnError="True">&
lt\asp:RequiredFieldValidator>

CompareValidator
<asp:CompareValidator ID="CompareValidator1"
runat="server"
ErrorMessage="CompareValidator">asp:CompareValidator>
Compares the value between 2 input
controls or 1 input control and 1 fixed value.
Example
<asp:CompareValidator ID="CompareValidatorBirthDay1"
<asp:CompareValidator ID="CompareValidatorBirthDay1"
runat="server"
ControlToValidate="txtFrom"
ErrorMessage="Invalid Date Range"
ForeColor="Red"
Operator="LessThanEqual"
SetFocusOnError="True"
ValueToCompare="01/01/1900"
ControlToCompare="txtTo"
Type="Date">asp:CompareValidator>

No comments:
Post a Comment