Topic: Validation - Creating validation controls
Share/Save/Bookmark
C# - Creating Validation Controls
 
RequiredFieldValidator     - Check whether a control contains data
CompareValidator           - Check whether an entered item matches an entry in another control (Set "TYPE" property)
RangeValidator             - Check whether an entered item is between two values (Set "TYPE" property)
RegularExpressionValidator - Check whether an entered item matches a specified format
CustomValidator            - Check the validity of an entered item using a client-side script or a
                             server-side code, or both
ValidationSummary          - Display validation errors in a central location or display a
                             general validation error description
                            
                            
To use the validation controls, follow these steps:
 
1. Draw a validation control on a Web form and set its "ControlToValidate" property to the control you want to validate.
    If you're using the CompareValidator cotnrol, you also need to specify the "ControlToCompare" property
2. Set the validation control's "ErrorMessage" property to the error message you want displayed if the control's data
    is not valid.
3. Set the validation control's "Text" property if you want the validation control to display a message other than the
    message in the "ErrorMessage" property when an error occurs. Setting the "Text" proprerty lets you briefly indicate
    where the error occurred on the form and display the longer "ErrorMessage" property in a Validation Summary control.
4. Draw a ValidationSummary control on the Web form to display the error messages from the validation controls in one place.
5. Provide a control that triggers a postback event. Although validation occurs on the client side, validation doesn't
    start until a postback is requested.
   
NOTES:
 
1. To display validation errors as a dialog box, set the ValidationSummary control's "ShowMessage" property to "True"
 
2. TIP: Use the RequiredFieldValidator control's "InitialValue" property to ignore instructions included in the control
    to validate. For example, if the control to validate is a DropDownList that includes an item in with the text
    "Select an item", enter "SELECT AN ITEM" in the RequiredFieldValidator's control's "InitialValue" property to make
    that selection invalid.