Get Relevant Control’s values From Validator

Here’s an example

<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" />
 <script language="javascript" type="text/javascript">
  function abc() {
    //there are 2 ways you can get the validator
    var val = Page_Validators[0];
    var val2 = $get('<%= Req1.ClientID %>');
    //Display all attributes of this validator
    alert("isvalid=" + val.isvalid);

    alert("isvalid=" + val2.isvalid);
    alert("controltovalidate=" + val2.controltovalidate);
    alert("errormessage=" + val2.errormessage);
    alert("validationGroup=" + val2.validationGroup);
    alert("id=" +;
    alert("initialvalue=" + val2.initialvalue);
  <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>
   <br />
   <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="abc();" 
    ValidationGroup="Group1" onclick="Button1_Click" />

This entry was posted in General ASP.Net C#. 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s