Hyperlink to go back to previous page in asp .net
If you are using asp.net then remember that
javascript:history.go(-1)
and
window.history.back()
Both will take you to back page.
But the previous page will not be exactly previous page.
For example
Suppose you are on page Default.aspx
and there is a asp:button
Now when you click on the button and you are back on Default.aspx
in this situation your previous page is still you Default.aspx
Take another exapmle
You have two pages Default1.aspx
and Default2.aspx
Condition 1:- button clicked on Default1.aspx
which redirect you to Default2.aspx
ok your previous page is Default1.aspx
Condition 2:- button clicked on Default1.aspx
and post back on the same Default1.aspx
page
Now your previous page is still Default1.aspx
Edit
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
ViewState["RefUrl"] = Request.UrlReferrer.ToString();
}
}
and use this in back button as follows
protected void Button3_Click(object sender, EventArgs e)
{
object refUrl = ViewState["RefUrl"];
if (refUrl != null)
Response.Redirect((string)refUrl);
}
you can use this:
<a href='javascript:history.go(-1)'>Go Back to Previous Page</a>
For Going to previous page
First Method
<a href="javascript: history.go(-1)">Go Back</a>
Second Method
<a href="##" onClick="history.go(-1); return false;">Go back</a>
if we want to more than one step back then increase
For going 2 steps back history.go(-2)
For going 3 steps back history.go(-3)
For going 4 steps back history.go(-4)
and so on........