Confusion about using Server.Transfer.

Discussion in 'ASP .Net' started by Ken Varn, May 6, 2005.

  1. Ken Varn

    Ken Varn Guest

    I have Page1 that does a transfer to page2. When the user is done with
    Page2, there is a button on Page2 that they can press to bring them back to
    Page1. I use Server.Transfer to navigate from one page to the next.

    The confusion that I am having is that when the user is done with Page2 and
    clicks on the button to bring them back to Page1, I want Page1 to basically
    come back with the exact same view that it had before the user navigated
    away from it. However, I notice that when Page1 comes back, the
    Page.IsPostback is set back to false, so all of my initialization code gets
    run. I also notice that my ViewState is gone. I was hoping that somehow
    the return trip back to the original page would behave something like a
    postback with the original Page1 ViewState intact.

    Maybe I am just not understanding how to do this correctly, but it seems
    like it should be pretty trivial to return back to a page as with its
    original state intact. The only other option I would have is to call
    JavaScript to navigate backwards in the history buffer, but that just
    doesn't seem right.


    --
    -----------------------------------
    Ken Varn
    Senior Software Engineer
    Diebold Inc.

    EmailID = varnk
    Domain = Diebold.com
    -----------------------------------
    Ken Varn, May 6, 2005
    #1
    1. Advertising

  2. Ken Varn

    Scott Allen Guest

    Hi Ken:

    ViewState is only effective when a form posts back to itself - in this
    scenario Page2 doesn't know how to write out the ViewState for Page1.

    I imagine your button is a hyperlink? You'll have to carry state
    across the pages by passing information in the querystring, or holding
    state on the server, like in the Session or Cache.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Fri, 6 May 2005 11:26:16 -0400, "Ken Varn" <nospam> wrote:

    >I have Page1 that does a transfer to page2. When the user is done with
    >Page2, there is a button on Page2 that they can press to bring them back to
    >Page1. I use Server.Transfer to navigate from one page to the next.
    >
    >The confusion that I am having is that when the user is done with Page2 and
    >clicks on the button to bring them back to Page1, I want Page1 to basically
    >come back with the exact same view that it had before the user navigated
    >away from it. However, I notice that when Page1 comes back, the
    >Page.IsPostback is set back to false, so all of my initialization code gets
    >run. I also notice that my ViewState is gone. I was hoping that somehow
    >the return trip back to the original page would behave something like a
    >postback with the original Page1 ViewState intact.
    >
    >Maybe I am just not understanding how to do this correctly, but it seems
    >like it should be pretty trivial to return back to a page as with its
    >original state intact. The only other option I would have is to call
    >JavaScript to navigate backwards in the history buffer, but that just
    >doesn't seem right.
    Scott Allen, May 6, 2005
    #2
    1. Advertising

  3. Ken Varn

    Ken Varn Guest

    It's my understanding that if I use Server.Transfer(NewUrl,true), then my
    forms QuerryString is passed to the new page, and I have confirmed that it
    does. The problem I am having, is there should be some way of having that
    postback data available if I transfer back to the original page, which I
    can't seem to figure out how to do. Somehow I need something like this
    (although I know this is not how to do it):

    Server.Transfer(OrigUrl, SavedFormPostbackData);

    Since the postback data is transferred to the new page, one would think that
    there would be a way to transfer it back to the calling page.


    --
    -----------------------------------
    Ken Varn
    Senior Software Engineer
    Diebold Inc.

    EmailID = varnk
    Domain = Diebold.com
    -----------------------------------
    "Scott Allen" <> wrote in message
    news:...
    > Hi Ken:
    >
    > ViewState is only effective when a form posts back to itself - in this
    > scenario Page2 doesn't know how to write out the ViewState for Page1.
    >
    > I imagine your button is a hyperlink? You'll have to carry state
    > across the pages by passing information in the querystring, or holding
    > state on the server, like in the Session or Cache.
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Fri, 6 May 2005 11:26:16 -0400, "Ken Varn" <nospam> wrote:
    >
    > >I have Page1 that does a transfer to page2. When the user is done with
    > >Page2, there is a button on Page2 that they can press to bring them back

    to
    > >Page1. I use Server.Transfer to navigate from one page to the next.
    > >
    > >The confusion that I am having is that when the user is done with Page2

    and
    > >clicks on the button to bring them back to Page1, I want Page1 to

    basically
    > >come back with the exact same view that it had before the user navigated
    > >away from it. However, I notice that when Page1 comes back, the
    > >Page.IsPostback is set back to false, so all of my initialization code

    gets
    > >run. I also notice that my ViewState is gone. I was hoping that somehow
    > >the return trip back to the original page would behave something like a
    > >postback with the original Page1 ViewState intact.
    > >
    > >Maybe I am just not understanding how to do this correctly, but it seems
    > >like it should be pretty trivial to return back to a page as with its
    > >original state intact. The only other option I would have is to call
    > >JavaScript to navigate backwards in the history buffer, but that just
    > >doesn't seem right.

    >
    Ken Varn, May 6, 2005
    #3
  4. Ken Varn

    Mike Salter Guest

    Ken:

    Sounds like a problem I just figured out. I needed to to open a page in a
    separate window, while preserving the original page. Try the code below.
    When the user is done with Page2, just close it.
    --
    Mike Salter
    (just another programmer)

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    ...
    string strBaseUrl = Request.Url.AbsoluteUri;
    strBaseUrl = strBaseUrl.Substring(0,strBaseUrl.LastIndexOf("/") + 1);
    Session["BaseURL"] = strBaseUrl;
    ...
    }
    }

    // Somewhere in your code you decide to show Page2
    string strBaseUrl = Session["BaseURL"].ToString();
    System.Web.HttpContext.Current.Response.Write("<script
    language=javascript>window.open('"
    + strBaseUrl
    + "Page2.aspx','new_Win');</script>");


    "Ken Varn" <nospam> wrote in message
    news:ugP%234$...
    >I have Page1 that does a transfer to page2. When the user is done with
    > Page2, there is a button on Page2 that they can press to bring them back
    > to
    > Page1. I use Server.Transfer to navigate from one page to the next.
    >
    > The confusion that I am having is that when the user is done with Page2
    > and
    > clicks on the button to bring them back to Page1, I want Page1 to
    > basically
    > come back with the exact same view that it had before the user navigated
    > away from it. However, I notice that when Page1 comes back, the
    > Page.IsPostback is set back to false, so all of my initialization code
    > gets
    > run. I also notice that my ViewState is gone. I was hoping that somehow
    > the return trip back to the original page would behave something like a
    > postback with the original Page1 ViewState intact.
    >
    > Maybe I am just not understanding how to do this correctly, but it seems
    > like it should be pretty trivial to return back to a page as with its
    > original state intact. The only other option I would have is to call
    > JavaScript to navigate backwards in the history buffer, but that just
    > doesn't seem right.
    >
    >
    > --
    > -----------------------------------
    > Ken Varn
    > Senior Software Engineer
    > Diebold Inc.
    >
    > EmailID = varnk
    > Domain = Diebold.com
    > -----------------------------------
    >
    >
    Mike Salter, May 12, 2005
    #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. Adrian Bezzina
    Replies:
    0
    Views:
    500
    Adrian Bezzina
    Aug 7, 2003
  2. gh0st54
    Replies:
    6
    Views:
    7,954
    Natty Gur
    Aug 19, 2003
  3. ewolfman
    Replies:
    4
    Views:
    3,336
    ewolfman
    Feb 13, 2006
  4. JT

    Server.Transfer vs. Server.Execute

    JT, Sep 9, 2003, in forum: ASP General
    Replies:
    1
    Views:
    80
    Ray at
    Sep 9, 2003
  5. Jim
    Replies:
    1
    Views:
    770
    Aaron Bertrand - MVP
    Jan 28, 2004
Loading...

Share This Page