This documentation is archived and is not being maintained.

ValidatorCollection Class

Exposes an array of IValidator references. This class cannot be inherited.

For a list of all members of this type, see ValidatorCollection Members.


[Visual Basic]
NotInheritable Public Class ValidatorCollection
   Implements ICollection, IEnumerable
public sealed class ValidatorCollection : ICollection, IEnumerable
public __gc __sealed class ValidatorCollection : public
   ICollection, IEnumerable
public class ValidatorCollection implements ICollection,

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Each IValidator reference is associated with a validation server control contained on the requested page. These controls add themselves to this collection when the Init method of the Page is called. They remove themselves when the Unload method of the Page is called. The Page class inherits both of these methods from the Control class.

You can access this collection, its methods, and its properties through the Page.Validators property. If the tested condition of any validator in this collection fails, the Page.IsValid property is set to false.


[Visual Basic, C#] The following sample demonstrates using the constructor and GetEnumerator method of the ValidatorCollection.

[Visual Basic] 
' Get 'Validators' of the page to myCollection.
Dim myCollection As ValidatorCollection = Page.Validators
' 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

// Get 'Validators' of the page to myCollection.
ValidatorCollection myCollection = Page.Validators;

// 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;

[Visual Basic, C#]

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Web.UI

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

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

See Also

ValidatorCollection Members | System.Web.UI Namespace | IValidator | Page.Validators