Form Validation Controls
Included in the Web Forms is a set of validation server controls that provide an easy-to-use but powerful way to check input forms for errors and if necessary, display messages to the user. Validation controls are added to a Web Forms page like other server controls.and there are controls for specific types of validation, such as range checking or pattern matching, plus a
RequiredFieldValidator that ensures that a user does not skip an entry field. You can attach more than one validation control to an input control. – For example, you might specify both that an entry is required and that it must contain a specific range of values.
Validation controls work with a limited subset of HTML and Web server controls. For each control, a specific property contains the value to be validated.
The following table lists the input controls that may be validated.
| Control |
Validation Property |
| HtmlInputText |
Value |
| HtmlTextArea |
Value |
| HtmlSelect |
Value |
| HtmlInputFile |
Value |
| TextBox |
Text |
| ListBox |
SelectedItem.Value |
| DropDownList |
SelectedItem.Value |
| RadioButtonList |
SelectedItem.Value |
The validation controls always perform validation checking in server code. However, if the user is working with a browser that supports DHTML, the validation controls can also perform validation using client script. With client-side validation, any errors are detected on the client when the form is submitted to the server. If any of the validators are found to be in error, the submission of the form to the server is cancelled and the validator's Text property is displayed. This permits the user to correct the input before submitting the form to the server. Field values are revalidated as soon as the field containing the error loses focus, thus providing the user with a rich, interactive validation experience.
Note that the Web Forms page framework always performs validation on the server – even if the validation has already been performed on the client. This helps prevent users from being able to bypass validation by impersonating another user or a preapproved transaction. Client-side validation is enabled by default.. If the client is capable, uplevel validation will be performed automatically. To disable client-side validation – Set the page's ClientTarget property to "Downlevel" ("Uplevel" forces client-side validation).