ValidatorCollection.Contains(IValidator) Méthode

Définition

Détermine si le contrôle serveur de validation spécifié est contenu dans la collection ValidatorCollection de la page.

public:
 bool Contains(System::Web::UI::IValidator ^ validator);
public bool Contains (System.Web.UI.IValidator validator);
member this.Contains : System.Web.UI.IValidator -> bool
Public Function Contains (validator As IValidator) As Boolean

Paramètres

validator
IValidator

Contrôle serveur de validation à vérifier.

Retours

true si le contrôle serveur de validation se trouve dans la collection ; sinon, false.

Exemples

L'exemple de code suivant illustre l'utilisation de la méthode Contains.

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");
}
 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

S’applique à

Voir aussi