Confusion about using Server.Transfer.

K

Ken Varn

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
-----------------------------------
 
S

Scott Allen

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.
 
K

Ken Varn

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
-----------------------------------
 
M

Mike Salter

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>");
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top