The requiredfeild vaildator should not validate if the control is disabled

1.9k views Asked by At

I am having two controls in that i have set the required field vaildators for that controls.my issues is for the time being i have set that two controls disabled but this required validator is checking if the two controls in the disabled mode.i am checking that required field validator while clicking the save button.how to overcome this?

<asp:DropDownList ID="DropDownList1" Width="150" runat="server" TabIndex="17" Enabled="false"
  AppendDataBoundItems="true">
    <asp:ListItem Selected="True" Text="--Select Company--"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DropDownList1"
  ValidationGroup="UserDetailsGroup" InitialValue="--Select Company--" ErrorMessage="*"></asp:RequiredFieldValidator>

texboxcontrol:

<asp:TextBox ID="AcquiredDate" runat="server" Width="150" TabIndex="18" Enabled="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="AcquiredDate"
    ValidationGroup="UserDetailsGroup" ErrorMessage="*"></asp:RequiredFieldValidator>

here the save button is the image button?

<asp:ImageButton ID="Save" runat="server" ImageUrl="~/Images/save-button.gif"
   OnClick="Save_Click" TabIndex="41" ValidationGroup="UserDetailsGroup" />

How to overcome this pblm either in server side or client side?

1

There are 1 answers

8
Tim Schmelter On BEST ANSWER

Disable the Validators:

RequiredFieldValidator3.Enabled = DropDownList1.Enabled
RequiredFieldValidator2.Enabled = AcquiredDate.Enabled