Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you disable caching on Modal dialogs in IE?

We have implemented a popup window as a modal dialog using the IE method:

window.showModalDialog('...aspx')

The target of the popup window is itself an ASP.Net web page.

Assume for the following steps that the popup has never been launched:

  1. Launch popup.
  2. Page_Load event handler executes on server side.
  3. Close popup.
  4. Immediately launch popup again.
  5. This time Page_Load event handler doesn't execute.

It's clear that the popup content is being cached because if at Step 4 we clear the temporary internet files the Page_Load event handler is executed the second time.

We have experimented with adding the following to the Head of the web page (as recommended by several other sources) but none of it seems to work.

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />

We have also seen places where the use of these is discouraged

Can anyone help?

like image 760
Andy McCluggage Avatar asked Dec 01 '08 12:12

Andy McCluggage


People also ask

How do I disable cache in IE?

Navigate to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings registry subkey. From the Edit menu, select New, DWORD Value. Enter a name of DisableCachingOfSSLPages, then press Enter. Double-click the new value, set it to 1 to disable caching of SSL pages, then click OK.

When the value of cache-control is set to no-cache ie disable cache?

cache-control: no-cacheThis token is changed on the origin server whenever the resource is updated. When a user returns to a page with a 'no-cache' resource, the client will always have to connect to the origin server and compare the ETag on the cached resource with one on the server.

Which http prevents the browser from caching the page?

The Cache-Control header This header prevents all caching of a particular Web resource when the no-cache value is specified by an HTTP 1.1 server. Pages that are kept out of the cache aren't accessible until the browser can recontact the Web server. So, servers should use the Cache-Control header sparingly.


3 Answers

Add a timestamp querystring variable to the URL of the dialog content - number of ticks since 1/1/08 or something - IE will treat it as a new page and ignore the cache.

like image 64
Greg Hurlman Avatar answered Oct 25 '22 06:10

Greg Hurlman


To clear cache add this in page load:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
like image 30
F. Dobon Avatar answered Oct 25 '22 06:10

F. Dobon


Given that the http-equiv directives don’t work (and arguably shouldn’t be used), and despite it unfortunately being in the hack category of solutions, I think we are going to have to go with this (posted by Greg)...

url = "<Some url with query string>"
var date = new Date();
window.showModalDialog(url + “&” + date.getTime(), ... );

It is strange that there is no definitive way to disable caching on these modal dialogs. I’m not sure whether using modal dialogs in web browsers is accepted as a "good idea" or not, but we are aware of at least some of the shortcomings and alternatives, but are just unfortunately unable to use them in this project.

Thanks for your suggestions.

like image 42
Andy McCluggage Avatar answered Oct 25 '22 07:10

Andy McCluggage