Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Back button page refresh - ASP.net

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

like image 840
SetiSeeker Avatar asked Apr 29 '10 12:04

SetiSeeker


2 Answers

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();
like image 186
Prutswonder Avatar answered Nov 15 '22 12:11

Prutswonder


These two lines solved the Chrome problem for me:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

And I use this optional line to tell the browser not to create a history entry for each request of the same page:

Response.Cache.SetAllowResponseInBrowserHistory(true);

Sources:

Most popular answer in this post

Optional line

like image 2
daniloquio Avatar answered Nov 15 '22 12:11

daniloquio