Sorry, my post wasn't specific enough. I was trying to shorten a previous
2 page post and got overly terse.
I'm writing a user control which has two states: Active & InActive. I
additionally am required that there to be only one active control per
page, and all logic has to be contained within the control.
In its inactive state, only a single button appears. If the user clicks
on this button, the control becomes active( the rest of the control's
functionality becomes visible), and all other controls should become
inactive. When the user is finished with a control, they click the 'Done'
button, and the control becomes inactive.
I'm trying to do this by having a session variable for each control,
Session[ this.ControlID + "_ActiveState"] = { 0, 1 } and a single session
variable
Session[ "WhichControlIsActive "] = { 'None', "ControlID_1", "ControlID2",
... , "ControlID_N" }
When the user selects an inactive control, its Session[ this.ControlID +
"_ActiveState"] gets set to 1 in the Control.ActivateButton_Click(..)
method, and Session[ "WhichControlIsActive" ] = this.ControlID;, and the
page gets posted back.
When the user is finished and clicks the 'Done' button, Session[
this.ControlID +"_ActiveState"] get set to 0, Session[
"WhichControlIsAcitve"] get set to 'None', and the page gets posted back.
I now want the new page to reflect the new session variables. My problem
is that the new session variables don't get saved until after the
Page_Load event of the new page, so these session variables are useless in
structuring the subsequent pages.
I can't use hidden fields, because they would have to be in a public place
( i.e. the containing page ), and I'm required to have all logic internal.
Similarly,
the Request.Form["_ "] isn't available to the controls.
Is there really no good way to do this?
Eliyahu Goldin said:
This is correct.
You can't do anything BEFORE the postback, since it is the postback that
cause your application to run. You probably mean "in the beginning" of
the postback handling code. Just put it in the beginning of Page_Load
event, if you can. If you need to know what caused the postback, you can
check Request.Form["__EVENTTARGET"] (works in most cases, but there are
exceptions), or pass it in your own hidden input.
Eliyahu
Phillip N Rounds said:
In diagnosing a problem, I noted that a button_click event gets run only
after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1,
C#)
Can this be correct? I'm trying to set session variables in a
Button_Click event which determines how the page is supposed to appear
in the PostBack, so of course it fails.
Where should I put my code so that the session variables are re-set
before the PostBack?
Thanks
Phil