Chapter 16A. Validation Controls in Web Forms

Your web application must verify that all of the data entered by users is valid. This once formidable task has been made easier by the validation controls that are included with the ASP.NET Web Forms framework. In this lesson I show you how to use the various validation controls.

The validation controls are located on the Validation tab of the Toolbox. These are the validation controls:

  • CompareValidator — This control is used to perform a data type check and to compare the values of two different controls.

  • CustomValidator — This control is used to perform custom validation. I cover the CustomValidator in Lesson 17A.

  • RangeValidator — This control is used to check that a given value is between two values.

  • RegularExpressionValidator — This control is used to compare a value against a regular expression. It is used to validate the formats of such things as email addresses and phone numbers.

  • RequiredFieldValidator — This control is used to ensure that a value has been entered.

  • ValidationSummary — This control displays a list of all of the validation errors on the page.

All of the validation controls (except ValidationSummary) use the following properties:

  • ControlToValidate — This is the ID of the control being validated. It is required.

  • Display — This property designates how the control is displayed. It has three possible settings: None, Static, and Dynamic. Static is the default. I show you an example that uses a combination of these settings later ...

Get ASP.NET 4 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.