简体   繁体   中英

CheckBox does not fire CheckedChanged event when unchecking the checkbox Dynamically in ASP.Net

Here I am having a checkbox in this update panel.

<asp:UpdatePanel runat="server" ID="LVCheckBoxes">
    <ContentTemplate>
            <ul>
                <li>
                    <asp:CheckBox ID="New" Text="New" AutoPostBack="true" runat="server" OnCheckedChanged="checkBoxCheck" /></li>
            </ul>
    </ContentTemplate>
</<asp:UpdatePanel >

All I am Trying to do is uncheck it on click of linkbutton. Which is working fine.

<asp:LinkButton id="LbUnCheck" runat="server" OnClick="LbUnCheck" ToolTip="New">UnCheck</asp:LinkButton>

But Along with it I also want to fire the check changed Event Which is not firing

protected void LbUnCheck(object sender, EventArgs e)
{
        LinkButton lb = (LinkButton)sender;
        CheckBox cb = (CheckBox)LVCheckBoxes.FindControl(lb.ToolTip);
        cb.CheckedChanged += checkBoxCheck;
        cb.Checked = false;

}


protected void checkBoxCheck(object sender, EventArgs e)
{
   //Do something

}

I even Tried this using JQuery but it is not working quite as expected.

Help Appreciated..!!

Try calling the CheckBox check event method ( checkBoxCheck ) from the Link Button click event method ( LbUnCheck ). Something like this:

protected void LbUnCheck(object sender, EventArgs e)
{
        LinkButton lb = (LinkButton)sender;
        CheckBox cb = (CheckBox)LVCheckBoxes.FindControl(lb.ToolTip);

        // cb.CheckedChanged += checkBoxCheck; // REMOVE THIS LINE

        cb.Checked = false;
        checkBoxCheck(null, null); // NOTICE THIS IS AFTER SETTING cb.Checked = false;
}


protected void checkBoxCheck(object sender, EventArgs e)
{
   //Do something
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM