Question re Event Firing Sequence

Discussion in 'ASP .Net' started by Phillip N Rounds, Mar 1, 2006.

  1. 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
    Phillip N Rounds, Mar 1, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
    Eliyahu Goldin, Mar 2, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>
    >>

    >
    >
    Phillip N Rounds, Mar 2, 2006
    #3
  4. First, I think Request.Form["_ "] should be available for controls as long
    as controls can get a pointer to the page they are on. Furthermore, the
    UserControl class already has property Request.

    Second, you don't need to access Request.Form["_ "] from the control in the
    first place, just do it in the Page_Load event and you will now what control
    initiated the postback.

    Am I again missing something?

    Eliyahu

    "Phillip N Rounds" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    >> 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" <> wrote in message
    >> news:...
    >>> 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
    >>>
    >>>

    >>
    >>

    >
    >
    Eliyahu Goldin, Mar 5, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Assaf

    Strange firing sequence???

    Assaf, May 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    284
    Assaf
    May 21, 2004
  2. Guadala Harry

    PostBack Event Firing Sequence

    Guadala Harry, Aug 15, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,017
    Bredal Jensen
    Aug 15, 2004
  3. GauravGupta
    Replies:
    4
    Views:
    2,080
    Shilpa1234
    Jan 19, 2012
  4. stef mientki
    Replies:
    13
    Views:
    616
    stef mientki
    Oct 20, 2007
  5. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,650
    rantingrick
    Jun 23, 2010
Loading...

Share This Page