Page.GetValidators(String) 方法

定義

傳回指定驗證群組的控制項驗證程式集合。

public:
 System::Web::UI::ValidatorCollection ^ GetValidators(System::String ^ validationGroup);
public System.Web.UI.ValidatorCollection GetValidators (string validationGroup);
member this.GetValidators : string -> System.Web.UI.ValidatorCollection
Public Function GetValidators (validationGroup As String) As ValidatorCollection

參數

validationGroup
String

要傳回的驗證群組,或 null 表示傳回預設的驗證群組。

傳回

ValidatorCollection

ValidatorCollection,包含指定驗證群組的控制項驗證程式。

範例

下列程式碼範例會 GetValidators 使用 方法來傳回預設驗證群組。

// Get 'Validators' of the page to myCollection.
ValidatorCollection myCollection = Page.GetValidators(null);

// Get the Enumerator.
IEnumerator myEnumerator = myCollection.GetEnumerator();
// Print the values in the ValidatorCollection.
string myStr = " ";
while ( myEnumerator.MoveNext() )
{
    myStr += myEnumerator.Current.ToString();
    myStr += " ";
}
messageLabel.Text = myStr;
' Get 'Validators' of the page to myCollection.
  Dim myCollection As ValidatorCollection = Page.GetValidators(Nothing)
' Get the Enumerator.
Dim myEnumerator As IEnumerator = myCollection.GetEnumerator()
' Print the values in the ValidatorCollection.
Dim myStr As String = " "
While myEnumerator.MoveNext()
    myStr += myEnumerator.Current.ToString()
    myStr += " "
End While
messageLabel.Text = myStr

備註

方法會 GetValidators 傳回與特定驗證群組相關聯的所有驗證物件。 您可以將 參數 null 設定為 , (與控制項相關聯的所有驗證控制項,) ValidationGroup 屬性設定 validationGroup 為 ,以傳回預設驗證群組。

若要驗證驗證群組的成員,您可以列舉集合,並呼叫 Validate 傳回之每個驗證程式的方法。

適用於

另請參閱