title: Enable/Disable asp:validators using jquery
body: <p>I am working with a wizard, where the user can sign up. There is a asp:RadioButtonList with two options, and some of the input fields in the wizard changes when the radiobutton changes. On each field there is some asp:Validators (asp:RequiredFieldValidator for example). The problem is, that when the user submits the page, the validator for the hidden textbox is still popping up.</p>
  
  <p>First, here is the div tags which changes the shown textboxes and the RadioButtonList</p>
  
  <pre><code>&lt;div id="divTxt1"&gt;
    &lt;asp:TextBox runat="server" CssClass="text" ID="txtNumber"
         type="number"/&gt;
    &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
         runat="server" ControlToValidate="txtNumber" EnableClientScript="true" ErrorMessage="Error" ToolTip="Error"&gt;*
     &lt;/asp:RequiredFieldValidator&gt;
  &lt;/div&gt;
  &lt;div id="divTxt2"&gt;
    &lt;asp:TextBox runat="server" CssClass="text" ID="txtNumber2"
         type="number"/&gt;
    &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
         runat="server" ControlToValidate="txtNumber2" EnableClientScript="true" ErrorMessage="Error2" ToolTip="Error2"&gt;*
     &lt;/asp:RequiredFieldValidator&gt;
  &lt;/div&gt;
  &lt;div id="radio"&gt;
  &lt;asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"&gt;
     &lt;asp:ListItem Value="1" Selected="True"&gt;Privat&lt;/asp:ListItem&gt;
     &lt;asp:ListItem Value="2"&gt;Offentlig&lt;/asp:ListItem&gt;
     &lt;/asp:RadioButtonList&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have tried to solve it using JQuery like the following, which I have read should do the trick, but unfortunately it doesn't:</p>
  
  <pre><code>$(document).ready(function () {
  
      $('#&lt;%= WizardStep1.ContentTemplateContainer.FindControl("RadioButtonList1").ClientID %&gt; input').change(function () {
          if ($(this).val() == "1") {
              $('#txtNumber').toggle('fast');
              $('#txtNumber2').toggle('fast');     
              ValidatorEnable($('#&lt;%=WizardStep1.ContentTemplateContainer.FindControl("RequiredFieldValidator1").ClientID %&gt;')[0], false);
              ValidatorEnable($('#&lt;%=WizardStep1.ContentTemplateContainer.FindControl("RequiredFieldValidator2").ClientID %&gt;')[0], true);
          }
  
          if ($(this).val() == "2") {
              $('#txtNumber').toggle('fast');
              $('#txtNumber2').toggle('fast');
              ValidatorEnable($('#&lt;%=WizardStep1.ContentTemplateContainer.FindControl("RequiredFieldValidator2").ClientID %&gt;')[0], false);
              ValidatorEnable($('#&lt;%=WizardStep1.ContentTemplateContainer.FindControl("RequiredFieldValidator1").ClientID %&gt;')[0], true);
          }
      });
  });
  </code></pre>
  
  <p>So, any ideas what's wrong?</p>