views:

424

answers:

2

I have an ASPX page that contains a link to "javascript:history.back()"

The problem is that page contains a gridview that changes with events (ex. a column is sorted). Now when I click the link to "javascript:history.back()", it just reverses the event but instead I want to go back to the last page (bypassing all the events).

Is there a simple way to do this?

+1  A: 

You'll have to save the referring page's URL when your page first gets called. Then use this URL in your "Back" links.

David
And as an added bonus, this could still work even when JavaScript is disabled...!
Shog9
A: 

use request.urlReferrer, put this in the hidden field when page is load, like....

  if (!Page.IsPostBack)

{
hdfRefrerPath.Value = Request.UrlReferrer.PathAndQuery.Substring(Request.UrlReferrer.PathAndQuery.LastIndexOf("/") + 1);
}

....where hdfRefrerPath is hidden field.

Muhammad Akhtar