views:

612

answers:

2

Hi,

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

A: 

The 'brute force' solution would be to put some javascript on the page that on page load sets the data to some known state. So it finds all the elements and sets the data based on an array of data or json object. On the initial request, since everything is defaulted anyways, the setting doesn't make a difference. On a back button request, since the javascript still has to be run, it resets all the values, regardless of browser.

I don't believe you can force a browser to function in the way you describe though, as it's up to each browser how they want to implement a back button - chrome just does it differently.

Tejs
A: 

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();
Prutswonder
SetiSeeker
It's a design choice by the Google folks I guess. I'm still glad they support he `autocomplete` attribute as a workaround.
Prutswonder