title: Dyanamically disable validation on asp.net controls
body: <p>Depending upon the responses from the user when they complete a form, controls may or may not be required.  All of these controls have validation attached to them.  For instance, if the user hasn't lived at their address for at least 2 years, I need to validate previous address information; if not, I need to skip that validation.</p>
  
  <p>I've tried disabling the validator control with jQuery and although when the validation text is 'greyed out', it still causes validation. </p>
  
  <pre><code>&lt;script src="../../Scripts/jquery-1.6.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $('#ddlSpouseData').change(
              function () {
                  var selection = $('#&lt;%= ddlAddressData.ClientID%&gt;').get(0).selectedIndex;
                  if (selection == 1) {
                      alert(selection);
                      $('#rfvAddressType').attr('disabled', 'disabled');
                      $('#rfvBAddress').attr('disabled', 'disabled');
                  }
  
              });
      });
  &lt;/script&gt;
  
         &lt;table id="MyTable" class="tableModule"&gt;
             &lt;tr&gt;
                  &lt;td class="tableDataBorder"&gt;
                      Data is not available and&lt;br /&gt; will be provided later.
                  &lt;/td&gt;
                  &lt;td class="tableDataBorder"&gt;
                      &lt;asp:DropDownList ID="ddlAddressData" runat="server"&gt;
                          &lt;asp:ListItem&gt;Please Select&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem&gt;Yes&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem&gt;No&lt;/asp:ListItem&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr class="hideRow"&gt;
                  &lt;td class="tableDataBorder"&gt;
                      Identifying Document
                  &lt;/td&gt;
                  &lt;td class="tableDataBorder"&gt;
                      &lt;asp:DropDownList ID="ddlAddressType" runat="server"&gt;
                          &lt;asp:ListItem&gt;Please Select&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem&gt;Home&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem&gt;Office&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem&gt;Other&lt;/asp:ListItem&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;br /&gt;
                      &lt;asp:RequiredFieldValidator ID="rfvAddressType" CssClass="regexError" ControlToValidate="ddlAddressType"
                          runat="server" ErrorMessage="Please select address type" Display="Dynamic"
                          InitialValue="Please Select"&gt;&lt;/asp:RequiredFieldValidator&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr class="hideRow"&gt;
                  &lt;td class="tableDataBorder"&gt;
                     Address
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="txtAddress" MaxLength="50" runat="server" CssClass="StdTxtBox"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                      &lt;asp:RequiredFieldValidator ID="rfvBAddress" CssClass="regexError" ControlToValidate="txtAddress"
                          runat="server" ErrorMessage="Please enter your address" Display="Dynamic"&gt;&lt;/asp:RequiredFieldValidator&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;/table&gt;
  </code></pre>