ValidatorCollection.Add(IValidator) Method

Definition

Adds the specified validation server control to the ValidatorCollection collection.

C#
public void Add(System.Web.UI.IValidator validator);

Parameters

validator
IValidator

The validation server control to add.

Examples

The following code example demonstrates how to use the Add method.

C#
Controls.Add(myForm);
myForm.Controls.Add(myLabel1);
myForm.Controls.Add(myTextBox);
myForm.Controls.Add(myButton);
this.Validators.Add(myRequiredFieldValidator);
myForm.Controls.Add(myLabel);
myForm.Controls.Add(myRequiredFieldValidator);

Remarks

When added to the ValidatorCollection collection of a Page object through the Validators property, the IValidator implementation takes part in validation. Its Validate method is called together with the Validate methods of all other validators. All validators then share in determining whether the Page object as a whole is valid.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also