More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

How to go back to previous page Options · View
hong
Posted: Thursday, February 17, 2011 5:57:22 AM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
There are several ways to go back to previous page:
1. using javascript
a.
Code:
<input type="button" value="Back to Previous Page" onclick="javascript: history.go(-1)">

b.
protected void Page_Load(object sender, EventArgs e)
Code:
{
      Button1.Attributes.Add("onClick", "javascript:history.back(); return false;")
}

2. using asp.net/c#
Code:
static string prevPage = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{
     if( !IsPostBack )
     {
         prevPage = Request.UrlReferrer.ToString();
     }
}

protected void Button2_Click(object sender, EventArgs e)
{
      Response.Redirect(prevPage);
}

3. using view state
Code:
For a server-side "Back"-function use:
Response.Redirect(Request.Referrer.AbsoluteUri);
This only works if it isn't a postback. If your page does postbacks use:
if(!IsPostBack)
{
ViewState.Add("ref",Request.UrlReferrer.AbsoluteUr i);
}
protected void Page_Load(object sender, EventArgs e)
{
     if( !IsPostBack )
     {
         prevPage = Request.UrlReferrer.ToString();
     }

}
Response.Redirect((string)ViewState["ref"]);

Sponsor
Posted: Thursday, February 17, 2011 5:57:22 AM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.066 seconds.