Export (0) Print
Expand All

ASP.NET validation controls

ASP.NET validation controls allow you to check user input on a web page. There are controls for different types of validation, such as range checking or pattern matching. Each validation control references an input control (a server control) elsewhere on the page. When user input is being processed (for example, when a page is submitted), the validation control tests the user input and sets a property to indicate whether the entry passed the test. After all of the validation controls have been called, a property on the page is set indicating whether any validation check has failed.

You can test the state of the page and of individual controls in your own code. For example, you would test the state of the validation controls before updating a data record with information entered by the user. If you detect an invalid state, you bypass the update. Typically, if any validation checks fail, you skip all of your own processing and return the page to the user. Validation controls that detect errors then produce an error message that appears on the page. You can display all validation errors in one place using a ValidationSummary control.

For more information about ASP.NET validation controls, see Learning More — Validation Controls in the MSDN library.

  • CompareValidator control   The CompareValidator control compares a user's entry against a constant value, against the value of another control (using a comparison operator such as less than, equal, or greater than), or for a specific data type. For information about programming the CompareValidator control, see CompareValidator Class in the MSDN library.

  • CustomValidator control   The CustomValidator control checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time. For information about programming the CustomValidator control, see CustomValidator Class in the MSDN library.

  • RangeValidator control   The RangeValidator control checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates. For information about programming the RangeValidator control, see RangeValidator Class in the MSDN library.

  • RegularExpressionValidator control   The RegularExpressionValidator control checks that the entry matches a pattern defined by a regular expression. This type of validation enables you to check for predictable sequences of characters, such as those in e-mail addresses, telephone numbers, postal codes, and so on. For information about programming the RegularExpressionValidator control, see RegularExpressionValidator Class in the MSDN library.

  • RequiredFieldValidator control   The RequiredFieldValidator control ensures that the user does not skip an entry. For information about programming the RequiredFieldValidator control, see RequiredFieldValidator Class in the MSDN library.

  • ValidationSummary control   The ValidationSummary control does not perform validation, but is often used in conjunction with other validation controls to display the error messages from all the validation controls on the page together. For information about programming the ValidationSummary control, see ValidationSummary Class in the MSDN library

Community Additions

ADD
Show:
© 2014 Microsoft