Hi,
I have an asp:DropDownList and Requiredfield Validator as below.
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem
Selected="True" Text="Choose Items"
Value=""></asp:ListItem>
<asp:ListItem Text="aa"
Value="aa"></asp:ListItem>
<asp:ListItemText="bb"
Value="bb"></asp:ListItem>
<asp:ListItemText="cc"
Value="cc"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="DropDownList1"
Display="Dynamic" ErrorMessage="Please Choose"
EnableClientScript="true"></asp:RequiredFieldValidator>
There are two more radio buttons,which toggles the visibility of Drop Down
list.
<asp:RadioButton
ID="RadioButton1" runat="server"
AutoPostBack="True" GroupName="Validate"
OnCheckedChanged="RadioButton1_CheckedChanged" Text="Make
Visible" />
<asp:RadioButton ID="RadioButton2" runat="server"
AutoPostBack="True" GroupName="Validate"
OnCheckedChanged="RadioButton2_CheckedChanged" Text="Make
In-Visible" />
In last there is a
Button.
<asp:Button
ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
Expected Behavior:
- When DropDown is Visible - If button is clicked then
system should popup Validator.
- When DropDown is In-Visible - If button is clicked then
system should not popup Validator.
Solution done by me:
protected void
RadioButton1_CheckedChanged(object sender, EventArgs e)
{
RequiredFieldValidator1.Enabled = true;
}
protected void
RadioButton2_CheckedChanged(object sender, EventArgs e)
{
RequiredFieldValidator1.Enabled = false;
}
Please help
to achieve this in a more better way.
Thanks & Regards,
Arun
Manglick || Tech Lead || AppliedSB – Digital Downloads || 620