Why my events aren't registered after postback?
- by lucian.jp
I have a problem where I have a page with a checkbox :
<asp:CheckBox runat="server" ID="chkSelectAll" OnCheckedChanged="chkSelectAll_CheckedChanged" EnableViewState="true" Text='<%# CommonFunctions.GetText(Page, "CreateTask", "chkSelectAll.text") %>' AutoPostBack="true" />
First I had the problem that when the event was raised the checkbox wasn't keeping the checked property value. This is still strange because nowhere in the application we set the EnableViewState to false and by default it should be true. Well this behavior was fixed by puting EnableViewState="true".
So now, I have a checkbox that when I first load the page, wworks correctly. I check the box, the event is raised Checked property valu is good and the method is executed. Postback completes and renders the page. I check the box back to false, the event is not triggered and the page is reloaded with the previous data but the Checked Property stays at true.
So after the first postback I seem to loose behavior of event and ViewState.
We suspect the fact that we move dynamically the controls in the page (See answer here)
But this suspicion doesn't explain why everything works perfectly after the first load and stops working after first PostBack.
EDIT
CODE SAMPLE
I created a test project where you can experience my problem. At load if you check any checkbox both raise their respective event. After postback only the second raise both events. I seem to have a problem when I register the events after moving control.