
Validators | 263
Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Validators
ValidatorCollection = Page.Validators
Returns an instance of the ValidatorCollection class containing all the validator
controls contained on the requested page. We can access each validator control by
iterating the ValidatorCollection collection.
Parameter
ValidatorCollection
An object variable of type ValidatorCollection.
Example
The code example displays a Textbox control with a RequiredFieldValidator and
RegularExpressionValidator control assigned to it. In Page_Load, the code iter-
ates through the ValidatorCollection returned by the Validators property and
displays the ID and ErrorMessage property of each validator in the collection:
<%@ Page Language="vb" %>
<html>
<head>
<title></title>
<script runat="server">
Sub Page_Load( )
Dim Validator as BaseValidator
For Each Validator in Validators
Message.Text &= Validator.ID & " error message: "
Message.Text &= Validator.ErrorMessage & "<br/>"
Next
End Sub
</script>
</head>
<body>
<form runat="server">
Phone: <asp:textbox id="phone" runat="server"/>
<asp:requiredfieldvalidator
id="rfvPhone"
controltovalidate="phone"
display="dynamic"
errormessage="Required!"
runat="server"/>
<asp:regularexpressionvalidator
id="revPhone"
controltovalidate="phone"
display="dynamic"
validationexpression="^[2-9]\d{2}-\d{3}-\d{4}$" ...