• Validation Controls

    A validation control enables us to validate an input and display an error message if necessary. It is very much like other server-side controls with certain additional methods and properties. First, the server treats it as an invisible control.

    After the user has entered erroneous data, it becomes visible. It is a powerful, rapid application development feature; however, a developer needs to understand its behavior and the methods thoroughly before he or she can appreciate it.

    There are certain rough edges in the Beta 2 version, which hopefully will be polished in the final product.The best strategy to learn the family of controls is to learn them one at a time, and finally to apply the summary validation.

    Various types of validation controls are as follows:

    1. RequiredFieldValidator Checks if the input control has any value.
    2. RegularExpressionValidator Checks the value against a regular expression (pattern).
    3. CompareValidator Checks if the value is acceptable compared to a given value or compared to the content of another control.
    4. RangeValidator Checks if the input control’s value is within a specified range.
    5. CustomValidator Allows you to develop custom validation.
    6. ValidationSummary Reports a summary of all errors.

    By default, each of the validation controls performs the validation task at the client-side as well as at the server-side. Except for the RequiredFieldValidator, all other validation controls treat an empty field as a valid field.Therefore, we will need to apply a RequiredFieldValidator to every input field that we want to validate.

    You can attach more than one validation control to an input.

    For example we may use a RequiredFieldValidator and a RangeValidator to ensure that an input
    is not empty and falls within a specified range.

    There are a number of common properties in these controls.The major ones are:

    1. ErrorMessage In case of an error, the system displays this message at the location of the control, and in the summary report, if any.

    2. Display A validation control is kept invisible until a bad input is entered. In case of a bad input, the system has to display the error message.

    The display mechanism can be handled in one of three ways.

    1. Display= “static” Initially, enough room in the page is reserved for the expected error message.

    2. Display= “dynamic” No room is initially reserved. In case of an error, the message is displayed by displacing existing contents of the page.

    3. Display=“none” The message won’t be displayed at the location of the control; however, it will be reported in the summary report, if any.


Leave a Reply