ValidatorCollection.Add(IValidator) 方法

定义

将指定的验证服务器控件添加到 ValidatorCollection 集合。Adds the specified validation server control to the ValidatorCollection collection.

public:
 void Add(System::Web::UI::IValidator ^ validator);
public void Add (System.Web.UI.IValidator validator);
member this.Add : System.Web.UI.IValidator -> unit
Public Sub Add (validator As IValidator)

参数

validator
IValidator

要添加的验证服务器控件。The validation server control to add.

示例

下面的代码示例演示如何使用 Add 方法。The following code example demonstrates how to use the Add method.

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);
Controls.Add(myForm)
myForm.Controls.Add(myLabel1)
myForm.Controls.Add(myTextBox)
myForm.Controls.Add(myButton)
Me.Validators.Add(myRequiredFieldValidator)
myForm.Controls.Add(myLabel)
myForm.Controls.Add(myRequiredFieldValidator)

注解

通过属性添加到 ValidatorCollection 对象的集合时 Page Validators ,实现将参与 IValidator 验证。When added to the ValidatorCollection collection of a Page object through the Validators property, the IValidator implementation takes part in validation. 它的 Validate 方法与 Validate 所有其他验证程序的方法一起调用。Its Validate method is called together with the Validate methods of all other validators. 然后,所有验证器将在确定 Page 对象是否为一个整体时进行共享。All validators then share in determining whether the Page object as a whole is valid.

适用于

另请参阅