Get All Validators For any control Clientside

Here’s an example

<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" />
 <script language="javascript" type="text/javascript">
  function abc() {
     var control = $get('<%= txt1.ClientID %>');
     for (var i = 0; i < control.Validators.length; i++) {
   <asp:TextBox ID="txt1" runat="server" ></asp:TextBox>
   <asp:RequiredFieldValidator ID="Req1" runat="server" ErrorMessage="Required 1" ControlToValidate="txt1"
    ForeColor="Red"  Text="Required 1" ValidationGroup="Group1"></asp:RequiredFieldValidator>
   <asp:RegularExpressionValidator ID="Reg1" runat="server" Display="Dynamic" ControlToValidate="txt1"
    ValidationExpression="^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z] \d[A-Z]\d$" ErrorMessage="Numeric Only" 
    ForeColor="Red" Text="Numeric Only" ValidationGroup="Group1">
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="abc();" 
    ValidationGroup="Group1" onclick="Button1_Click" />

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s