1

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?

2 Answers 2

3

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
}
Sign up to request clarification or add additional context in comments.

4 Comments

No no.I have some panel with control inside them.according some condition I enable and disable them.I want to validate Enabled panel's controls
you can disable all the validators of respected controls, see my edited answer
this is a solution but is not exist another better way?
other thing is i told you already set CausesValidation to false
0

Add this line in Page_Load()

RequiredFieldValidator1.Enabled = panel.Enabled;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.