O'Reilly logo

ASP.NET 4 24-Hour Trainer by Toi B. Wright

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required