Validation Server Controls
Validation server controls are a collection of controls that allow you to validate an associated input server control, such as a TextBox, and display a custom message when validation fails. Each validation control performs a specific type of validation. For example, you can validate against a specific value or a range of values by using the CompareValidator and RangeValidator controls, respectively. You can even define your own validation criteria by using the CustomValidator control. Since the error message is displayed in the validation control, you can control where the message is displayed on the Web page by placing the validation control at the desired location. You can also display a summary of the results from all validation controls on the page by using the ValidationSummary control.
By default, page validation is performed when a button control, such as Button, ImageButton, or LinkButton, is clicked. You can prevent validation from being performed when a button control is clicked by setting the CausesValidation property of the button control to false. This property is normally set to false for a cancel or clear button to prevent validation from being performed when the button is clicked.
The following topics cover the ASP.NET syntax you must use when you want to create one of the validation controls in a text or HTML editor. These topics include information about all properties that are shared among all validation controls, as well as specific properties for each control that you can declare as an attribute within a specified control's opening tag.
In This Section
- Base Validation Control Properties
- Details the properties that are shared by all validation controls.
- Base Compare Validation Control Properties
- Details the properties that are shared by all validation controls that perform typed comparisons, such as CompareValidator and RangeValidator.
- CompareValidator Control
- Details the ASP.NET syntax for the CompareValidator control. You can use this control to compare a user's entry against a constant value or the value of another control. The comparison operator determines what type of comparison to make (less than, equal, greater than, and so on).
- CustomValidator Control
- Details the ASP.NET syntax for the CustomValidator control. You can use this control to create custom server and client validation code.
- RangeValidator Control
- Details the ASP.NET syntax for the RangeValidator control. You can use this control to check whether a user's entry is between a specified upper and lower boundary. You can check ranges within pairs of numbers, alphabetic characters, and dates. Boundaries are expressed as constants.
- RegularExpressionValidator Control
- Details the ASP.NET syntax for the RegularExpressionValidator control. You can use this control to check that the entry matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on.
- RequiredFieldValidator Control
- Details the ASP.NET syntax for the RequiredFieldValidator control. You can use this control to ensure that the user does not skip an entry.
- ValidationSummary Control
- Details the ASP.NET syntax for the ValidationSummary control. This control displays a summary of all validation errors for all the validation controls on a page.
- System.Web.UI.WebControls Namespace
- Describes the WebControls namespace.