ValidatorCollection.Contains(IValidator) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定的验证服务器控件是否包含在页的 ValidatorCollection 集合内。
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
参数
- validator
- IValidator
要检查的验证服务器控件。
返回
如果验证服务器控件位于集合中,则为 true
;否则为 false
。
示例
下面的代码示例演示如何使用 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