title: Disable RequiredFieldValidator in asp.net c#
body: <p>I am trying to disable a RequiredFieldValidator by radio button list value. I have it coded but it doesn't seems to be working.</p>
  
  <p>What i have done so far: </p>
  
  <pre><code>protected void radioButtonList(object sender, EventArgs e)
          {
    if (((RadioButtonList)dvInsertPromotion.FindControl("RadioButtonList2")).SelectedValue == "Y")
              {
                  ((RequiredFieldValidator)dvInsertPromotion.FindControl("rfvdate1")).Enabled = false;
                  ((RequiredFieldValidator)dvInsertPromotion.FindControl("rfvdate")).Enabled = false;
                  this.addPromotion.Show();
              }
              else
              {
                  ((RequiredFieldValidator)dvInsertPromotion.FindControl("rfvdate1")).Enabled = true;
                  ((RequiredFieldValidator)dvInsertPromotion.FindControl("rfvdate")).Enabled = true;
                  this.addPromotion.Show();
              }
  }
  </code></pre>
  
  <p>html:</p>
  
  <pre><code> &lt;asp:RadioButtonList ID="RadioButtonList2" runat="server" ValidationGroup="addValidationGp" OnSelectedIndexChanged="radioButtonList"&gt;
                                       &lt;asp:ListItem Text="Yes" Value="Y"&gt;&lt;/asp:ListItem&gt;
                                       &lt;asp:ListItem Text="No" Value="N" Selected&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:RadioButtonList&gt;
                                      &lt;asp:TextBox ID="txtPubDate" Width="75"  MaxLength="10" runat="server" AutoPostBack="true" OnTextChanged="insertStartEndDateTime_SelectedIndexChanged"/&gt;
                                  &lt;asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtPubDate"
                                      PopupPosition="Right" Format="dd/MM/yyyy" /&gt;
                                  &lt;asp:RequiredFieldValidator ID="rfvdate" ValidationGroup="addValidationGp" runat="server"
                                      ControlToValidate="txtPubDate" ErrorMessage="*" Display="Dynamic" Enabled="true"
                                      SetFocusOnError="true" /&gt;&lt;br /&gt;
  </code></pre>