ValidatorCollection.Remove Method (IValidator)

 

Removes the specified validation server control from the page's ValidatorCollection collection.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public void Remove(
	IValidator validator
)

Parameters

validator
Type: System.Web.UI.IValidator

The validation server control to remove from the collection.

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

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


// Remove the RequiredFieldValidator.
if(Validators.Contains(myRequiredFieldValidator))
{
   this.Validators.Remove(myRequiredFieldValidator);
   Response.Write("RequiredFieldValidator is removed from ValidatorCollection<br>");
   Response.Write("ValidatorCollection count after removing the Validator: "+Validators.Count+"<br>");
}
else
{
   Response.Write("ValidatorCollection does not contain RequiredFieldValidator");
}

.NET Framework
Available since 1.1
Return to top
Show: