ValidatorCollection.Contains Method (IValidator)

 

Determines whether the specified validation server control is contained within the page's ValidatorCollection collection.

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

Public Function Contains (
	validator As IValidator
) As Boolean

Parameters

validator
Type: System.Web.UI.IValidator

The validation server control to check for.

Return Value

Type: System.Boolean

true if the validation server control is in the collection; otherwise, false.

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

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

' Remove the RequiredFieldValidator.
 If Validators.Contains(myRequiredFieldValidator) Then
    Me.Validators.Remove(myRequiredFieldValidator)
    Response.Write("RequiredFieldValidator is removed from ValidatorCollection<br>")
    Response.Write("ValidatorCollection count after removing the Validator: " + Validators.Count.ToString() + "<br>")
 Else
    Response.Write("ValidatorCollection does not contain RequiredFieldValidator")
 End If

.NET Framework
Available since 1.1
Return to top
Show: