Checkbox.CheckedChanged has a mind of its own

  • Thread starter Thread starter Greg Hurlman
  • Start date Start date
G

Greg Hurlman

I've got a very simple ASCX page, where once someone finishes a section and
clicks the "Next >" button, the section they just finished is disabled, and
the next section appears below it, and so on. One of the controls is a
checkbox, which, when clicked, displays a hidden panel containing controls
whose input are used for filtering query results.

If someone checks the checkbox in the first section and clicks the first
"Next >" button, the checkbox stays checked, all is well. Problem is, on
the next postback, CheckedChanged is being called again on the first
checkbox, which has definitely not been changed by the user (remember, it's
disabled)!

Viewstate is not disabled in the ASCX control or the parent ASPX page,
though I'm sure it has something to do with a hole in my page lifecycle
knowledge... any suggestions?
 
I did a simple test and you are correct. When viewstate is disabled the
checkbox will keep firing.

The reason is the checkbox has no idea what its previous state is because
viewstate is disabled. So when the user postback data is processed for the
checkbox, the checkbox doesn't know what the previous state is, but it does
detect data coming in from the form, so it assumes an event must be fired. I
tried textbox and the same happens there.

- J
 
You misread... ViewState is *not* disabled... if it were, I would've moved
on by now. :)
 
Oops sorry about that.

Well then I modified my simple example to use viewstate, I disabled the
checkbox after its clicked, and I no longer get the event. So it may be
something you are doing in code.

- J
 
Sure... I've zipped & attached the host ASPX page, ASCX file, and their
code-behind files. In addition, I failed to mention earlier that the
control is being dynamically loaded in the host page, but I have tested it
being explicitly declared, and I get the same results.

Thanks for your help!
 
Back
Top