OnCheckedChanged event not being triggered when checbox unchecked

648 Views Asked by At

I am trying to implement a checkbox logic. When the checkbox is checked the textbox will be enabled and vice versa.

When the checkbox checked, the event is triggered. However when the checkbox is unchecked, the event isn't triggered.

Here are the codes for checkbox;

<asp:CheckBox ID="CheckBox" runat="server" Checked="false" OnCheckedChanged="CheckedChanged" CssClass="LabelText" EnableViewState="False"  AutoPostBack="True" />

Here is the event block;

protected void CheckedChanged(object sender, EventArgs e)
    {
            txtIP.Enabled = CheckBox.Checked;

    }

In the debug mode I can see that , in the case of checked, method of CheckedChanged is being calling and textbox enabled but in the case of unchecked nothing happens, just loading the page.

I couldn't see my mistakes, I hope you'll help me guys.

Thnx.

1

There are 1 best solutions below

0
On BEST ANSWER

Try removing the Checked="false" and set EnableViewState="True":

<asp:CheckBox ID="CheckBox" runat="server" OnCheckedChanged="CheckedChanged" 
    CssClass="LabelText" EnableViewState="True" AutoPostBack="True" />

I've just tested this and it works correctly (without a master page). Bear in mind that you could also have EnableViewState set at the master page level.