9

Possible Duplicate:
detect back button click in browser

I have two pages, Page1 and Page2. When moving from Page1 to Page2 by clicking a link, I tend to store the conditions required to restore the state of Page1 on clicking browser back button when on Page2.

I am using the below function to clear the cache,

protected override void OnInit(EventArgs e)
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();
    Response.Cache.SetExpires(DateTime.MinValue);
    base.OnInit(e);
}

so that I can reload the page based on stored conditions in the cookie. But the issue is how to identify if I have pressed the browser back button or the menu link to come to Page1.

Update:

i just landed on this link detect back button click in browser but it doesn't work for me

Community
  • 1
  • 1
iJade
  • 23,144
  • 56
  • 154
  • 243
  • 4
    http://stackoverflow.com/questions/6359327/detect-back-button-click-in-browser – GeorgesD Dec 19 '12 at 10:30
  • 1
    I'd store location and navigation info in some session variables, to be handled accordingly so you can know where you are, where you were, and how you got where you are now. – Alex Dec 19 '12 at 10:33
  • @GeorgesD it does'nt solve my issue – iJade Dec 19 '12 at 10:57

1 Answers1

0

Please explain your problem, not your solution. Because you set the cacheability of your page to none, the browser will simply re-issue an unconditional request for the page. This is no different than clicking a link to that page and will not be detectable.

If your problem is that you don't know how to set form data when someone revisits a page, you could use a session like this (psuedo):

if (!String.IsNullOrEmpty(Session["Username"]))
{
    UsernameTextbox.Text = Session["Username"];
}

If you want to show a clear form when the link to that page is clicked, you could set a query parameter like reset=true, which will clear the session data and show a blank form.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • here is a link to my problem...http://stackoverflow.com/questions/13931677/unable-to-read-the-selected-drop-down-list-value-on-page-load-after-pressing-bro – iJade Dec 19 '12 at 11:44