Reputation: 13457
I have a Panel
control that contains some control such as text boxes.I want to use asp.net validators to validate text boxes.But if Panle
is disabled then text boxes become disabled but validators such as RequiredFieldValidator
validate disabled text box.
<asp:Panel ID="Panel1" runat="server" Enabled="false">
<asp:TextBox ID="TextBox2" runat="server" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="RequiredFieldValidator"
ForeColor="#FF3300" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</asp:Panel>
How I can set for validators that don't validate disabled controls?
Upvotes: 1
Views: 4494
Reputation: 121
Add this line in Page_Load()
RequiredFieldValidator1.Enabled = panel.Enabled;
Upvotes: 0
Reputation: 3911
if some control is disabled you can set its property CausesValidation="False"
<asp:Button id="Button1" runat="server"
Text="Cancel" CausesValidation="False">
</asp:Button>
EDITED
can you do this way
if (!panel.Enabled)
{
RequiredFieldValidator1.Enabled = false;// disable your all validators
}
Upvotes: 3