Checkbox not entering OnCheckChanged first time
<ajaxtoolkit:AccordionPane ID="accordianPaneAroundTheCheckbox" runat="server">
<Content>
<asp:UpdatePanel ID="updatePanelAroundTheCheckbox" runat="server" >
<ContentTemplate>
<div>
<asp:CheckBox ID="chkFoo" AutoPostBack="true" runat="server" OnCheckedChanged="DoBar"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</Content>
</ajaxtoolkit:AccordionPane>
We have something like the above. Extra stuff has been left off as it is a large page.
I place a breakpoint at the begining of Page_Load
and DoBar
. The first time I click the checkbox, the breakpoint on Page_Load
is hit, but DoBar
is not. The second time I click the checkbox, both breakpoints are hit.
Why could this be happening? I'm not dynamically generating the checkbox. It's ClientID is the same every time (no dynamically generated or ID'd containers). I've tried resubscribing to the event in the Page_Load
, but it didn't hit the first time, and just hit it subsequent times twice.开发者_开发百科
Update I have tried removing the UpdatePanel completely. Not only does the whole page postback, which I don't want, but the event is still not entered. What can block/swallow an event call like that? Is there some exception deep in the bowels of a master page or framework call or something somewhere that I can't see?
Is that the correct source code you've pasted? I'm asking because there's no event called OnCheckChanged, there is however an OnCheckedChanged event. Using your code it works just fine when the markup for the checkbox looks like this:
<asp:CheckBox ID="chkFoo" runat="server" AutoPostBack="true" OnCheckedChanged="DoBar"/>
The checkbox isn't being set by anything on the server side. The form is populated by an ajax call to a PageMethod that pulls a databag from the server and populates the controls. The problem is that the server thought it was unchecked, but javascript checked it. When I unchecked it, the postback happened, and the viewstate still thought its previous state was unchecked, and the current state is now unchecked. Thus, the CheckedChanged event doesn't fire.
A thousand grisly deaths to Viewstate. I'm close enough to fix the issue now. Thanks for trying/looking.
精彩评论