.NET Samples - ASP.NET Server Control Form Validation

This section includes the following samples:

Validator8 Sample

Validator7 Sample

Validator5 Sample

Validator4 Sample

Validator9 Sample

Validator3 Sample

Validator1 Sample

Validator2 Sample

Validator6 Sample

Validator8 Sample

This sample demonstrates the CustomValidator server control, which calls a user-defined function to perform validations that the standard validators can't handle.

Namespaces used in this sample:

(none)

Classes used in this sample:

Font; CustomValidator; Page; RequiredFieldValidator; Control; EventArgs; ServerValidateEventArgs; Button; Label; Message; Exception; TextBox

Validator7 Sample

This sample demonstrates the RegularExpressionValidator server control, which checks whether the entry matches a pattern defined by a regular expression.

Namespaces used in this sample:

(none)

Classes used in this sample:

Font; TextBox; RegularExpressionValidator; RequiredFieldValidator; Control; Page; Button; Object; Label; EventArgs

Validator5 Sample

This sample demonstrates the use of the RangeValidator server control, which tests whether an input value falls within a given range.

Namespaces used in this sample:

(none)

Classes used in this sample:

Font; Type; String; Button; RangeValidator; Page; Label; TextBox; Control; EventArgs; Object

Validator4 Sample

This sample demonstrates the CompareValidator server control, which compares the values of two other controls.

Namespaces used in this sample:

(none)

Classes used in this sample:

ListItem; Button; TextBox; String; Page; Object; CompareValidator; ListBox; Control; Type; EventArgs; Font; Label

Validator9 Sample

This sample shows a typical registration form, using the variations of validation controls discussed in this topic.

Namespaces used in this sample:

(none)

Classes used in this sample:

ListItem; Font; Control; RequiredFieldValidator; Message; TextBox; RegularExpressionValidator; Type; Regex; CompareValidator; Button; DropDownList; RadioButtonList; RadioButton; CustomValidator; Page; Convert; ValidationSummary; Array; Header; Form

Validator3 Sample

This sample illustrates displaying errors with a ValidationSummary control, which polls each of the validation controls on the page and aggregates the text messages exposed by each.

Namespaces used in this sample:

(none)

Classes used in this sample:

ListItem; RequiredFieldValidator; Button; DropDownList; Form; RadioButton; RadioButtonList; Message; TextBox; ValidationSummary; Control; Font; Type; Header; Object; Page; EventArgs

Validator1 Sample

This sample illustrates this using the RequiredFieldValidator server control. The simplest form of validation is a required field. If the user enters any value in a field, it is valid. If all the fields on the page are valid, the page is valid.

Namespaces used in this sample:

(none)

Classes used in this sample:

ListItem; RequiredFieldValidator; Button; DropDownList; RadioButton; RadioButtonList; TextBox; Control; Font; Page; Label; Object; Type; EventArgs

Validator2 Sample

This sample demonstrates the client-side validation capability of the ASP.NET validation controls. Client-side validation is enabled by default. If the client is capable, uplevel validation is performed automatically. To disable client-side validation, set the page's ClientTarget property to Downlevel (Uplevel forces client-side validation).

Namespaces used in this sample:

(none)

Classes used in this sample:

ListItem; RequiredFieldValidator; Page; Button; RadioButton; DropDownList; RadioButtonList; Message; TextBox; Control; Font; Label; Object; Type; EventArgs

Validator6 Sample

This sample demonstrates the RegularExpressionValidator server control, which checks whether the entry matches a pattern defined by a regular expression.

Namespaces used in this sample:

(none)

Classes used in this sample:

RegularExpressionValidator; Font; TextBox; Page; Button; Object; Label; Control; EventArgs