Going back to calling page

  • Thread starter Thread starter BillGatesFan
  • Start date Start date
B

BillGatesFan

Let's say I'm in a.aspx and I do a response.redirect to b.aspx. Then I
show and hide a couple of panels in b.aspx and now I want to click a
button to take me back to a.aspx. how do I do that without doing
response.redirect?
 
You can use the meta tags or javascript to move the page client side, or
server.transfer server side...I would redirect to the referrer.
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
The problem with it was I needed to go back to the correct page. My
example was kind of wrong. I'm on c.aspx, a.aspx and b.aspx could get to
c.aspx. How do I get back to the correct one that got me to c.aspx? If I
knew which one, then I could use response.redirect.
 
One method is to add the referer to Viewstate the first time the page
is loaded (Postback == false). This example uses a button, but once you
have the referer you can do whatever you want with it.

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BackPath = Request.UrlReferrer.ToString();
ViewState.Add("BackPath", BackPath);
}
else
{
BackPath = ViewState["BackPath"].ToString();
}
}

private void btnBack_Click(object sender, System.EventArgs e)
{
Response.Redirect(BackPath, false);
}

There are some other, more sophisticated approaches. Juval Lowy has
written a server control that handles this functionality:
http://www.ftponline.com/vsm/2003_07/magazine/columns/qa/
- Jon
http://weblogs.asp.net/jgalloway
 
Back
Top