views:

478

answers:

4

There are a few similar questions posted here but none that really addresses my needs.

I have a list of items on one page, lets call it masterlist.aspx. If I click on one these list items another page appears, i.e. details.aspx?id=something.

The page that appears has a formview control in edit mode. If the user wants to edit the data they hit an edit linkbutton and, the form is sent into edit mode, they then edit the data and click the save button, saving the data and putting the formview back in view mode.

The issue is if the user uses the browser back button to go back to the masterlist.aspx page the page is not updated, it's pulled out of the browser cache.

I have played around with the HTTP headers cache settings but can't get anything that works on all major browsers. On some browsers I get web page expired warnings. Another option is to somehow trigger a page refresh (or partial page refresh) when the page loads using client side code, but I haven't been able to figure out how to do this.

Is there any other approach or has anyone been successful with the two approaches above, or is there some way of avoiding the issue completely.

A: 

What about capturing the Back button keypress event, then instead of allowing it do a browser.history.back(), you can do a document.location(...) call.

Alternatively, you could capture the back event and trigger a post-back, which could do a Response.Redirect("yourpage"). This would force the browser to issue a GET statement for the designated page, and make it refresh

Josh E
A: 

With Javascript a complete solution may not be possible, but there is a workaround.

http://www.boutell.com/newfaq/creating/backbutton.html

It uses a timeout function that repeatedly forces the browser to perform a 'Forward' action. Even if someone clicks the Back button, it'll bring back to the actual page, thereby nullifying the Back operation. It may cause a flicker though.

whoopy_whale
Be careful of this method if you have any form elements on the page (like a login form). It has the potential to refresh the page while the user is typing into the fields.
Casey Watson
A: 

I have played around with the HTTP headers cache settings but can't get anything that works on all major browsers. On some browsers I get web page expired warnings.

How do you get to that masterlist page? If you issue an HTTP GET and prevent clients and proxies to cache it you'd have no issues navigating back to it (and still getting an updated version).

That leaves you with server side caching (with proper invalidation when any of those items change) or no caching at all.

+5  A: 

I have to do something like this in a catalog where the browse page needs to be loaded from the DB on every load because when you hit a product page it calls out to a 3rd party to get updated info, and then save it if it should be updated. This is so when you hit the back button like you're saying the data is reloaded. What I've done is added this into the page and it seems to work fine in all browsers.

public class ProductBrowser : Page
{
    protected override void OnInit(EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        Response.Cache.SetExpires(DateTime.MinValue);

        base.OnInit(e);
    }
}
Brian Surowiec
worked for my coworker in chrome and ie 6.
Merritt