3

I am developing a web application in ASP.NET and on some pages I want to prevent them from caching the data using the following code:

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

    base.OnInit(e);
}

This works like it should, but now when the user tries to refresh the page after a postback (e.g. saving the data) the browser informs the user that action will be caused twice if he proceeds and asks you if you want to continue or not. If you cancel this on Chrome or Firefox the page still has its current state - which is exactly what I want, but in IE it is invalidated.

Is there any way to achieve the same behaviour for Internet Explorer?

Bautzi89
  • 346
  • 1
  • 5
  • 21

1 Answers1

1

You probably need to take a different approach. Try creating a custom confirmation box to catch/cancel the refresh action:

http://devzone.co.in/show-confirmation-box-page-refresh-page-unload-using-javascript/

Execute function before refresh (although this solution has a comment that says it doesn't work on FireFox).

Community
  • 1
  • 1
Ian
  • 4,169
  • 3
  • 37
  • 62
  • Nice approach. Unfortunately I couldn't really get it working, but I'll keep trying. Or maybe I'll simply have to tell everyone not to use the fu##### IE ;) – Bautzi89 May 11 '15 at 08:53