Chrome Back button page refresh - ASP.net

SetiSeeker picture SetiSeeker · Apr 29, 2010 · Viewed 14k times · Source

I have an ASP.net application (c#).

When a user is on a specific page, they click a link on this page that takes them to a child page, displaying the product details.

If the user clicks the browser back button, I need the parent page to be refreshed to its initial state. ie all text boxes that had data typed need to be blank, any hidden fields reset etc. Basically i need a CTRL-F5 when a user clicks back.

Disabling the back button is not an option.

I need this only on certain pages.

In IE and Firefox i can get this working without an issue. But with chrome the textboxes still contain their values as do the hidden fields. If I hit CTRL-F5 in Chrome, the page is correctly reset to its initial state.

This is the code I have tried.

<%@ OutputCache Location="None" VaryByParam="None" %>

and this:

   Response.Buffer = true;
   Response.Cache.SetCacheability(HttpCacheability.NoCache);
   Response.Cache.SetAllowResponseInBrowserHistory(false);
   Response.Cache.SetNoStore();

and this:

    Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();

I have also tried a variety of these in different combination, but with no success.

thanks

Answer

Prutswonder picture Prutswonder · Apr 29, 2010

When the browser's back button is pressed, the INPUT fields are not reset automatically by the browser. Instead, the browser retains the user's input, making it easier for users to go back and make a change to the input.

You cannot solve this server-side, because the browser bypasses the cache for this. Instead, you can use the autocomplete="off" HTML attribute on the input fields to prevent them from being retained by the browser.

You can also manually reset the form using JavaScript:

document.getElementById("form1").reset();