Simon Harvey wrote:
I have a page that contains amongst other things, a check box that is set
according to a session variable.
When the page loads, the check box is set according to the session variable.
Now here's the weird bit. If I change the checkbox and press the button that
I've also made, the checkbox.Checked property is still set to whatever it
was set to when the page loaded.
It's like its ignoring the fact that the checkbox was changed.
It's likely caused because in your Page_Load event handler you're ALWAYS
setting the CheckBox' Checked property based on the Session variable
value, right? That is, you have something like:
Sub Page_Load(...)
myCB.Checked = Session("Blah")
End Sub
Instead, you should use:
Sub Page_Load(...)
If Not Page.IsPostBack then
myCB.Checked = Session("Blah")
End If
End Sub
Why? Well, the Page_Load event handler ALWAYS runs before ANY Web
control event handlers. So if you have, say, the CheckBox's
CheckChanged event wired up to some event handler, by the time that
runs, the CheckBox will have been reset back to the Session variable
value from the Page_Load event handler.
Does this make sense? I'm not 100% certain I'm directly addressing your
question... let me know if this doesn't clear things up... Thanks!
--
Scott Mitchell
mi******@4guysfromrolla.com http://www.4GuysFromRolla.com http://www.ASPFAQs.com http://www.ASPMessageboard.com
* When you think ASP, think 4GuysFromRolla.com!