Checkbox.CheckedChanged has a mind of its own

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?
 
N

NoOne

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
 
G

Greg Hurlman

You misread... ViewState is *not* disabled... if it were, I would've moved
on by now. :)
 
N

NoOne

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
 
G

Greg Hurlman

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top