How do you disable caching on Modal dialogs in IE?

13,025

Solution 1

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.

Solution 2

To clear cache add this in page load:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Solution 3

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.

Solution 4

First i tried by using the following code.

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

but it was not given any solution after, i tried with Query String with time stamp variable, like

vat time = new Date().getTime();

url?queryString&time=time

then it works....

Thanks...

Solution 5

Place Fiddler in between the IE and your server. Then check if the response to your request carries a HTTP header Cache-Control. Is there some value given other than no-cache ? If so then maybe IE will give this header priority over your http-equiv directive.

If not, you should try to make the server send the HTTP header Cache-Control:no-cache. If IE does not respect this, it's a bug in IE. Experience shows it's less painfull to opt for a different solution than to press for a bugfix, so in this case I'd agree to the tip of Greg.

Share:
13,025
Andy McCluggage
Author by

Andy McCluggage

Updated on July 22, 2022

Comments

  • Andy McCluggage
    Andy McCluggage almost 2 years

    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?

  • Craig Fisher
    Craig Fisher almost 13 years
    This will give you multiple instances of the page in the IE cache though.
  • CertifiedCrazy
    CertifiedCrazy about 10 years
    Additional clarification or examples should be added to justify this pattern over the Cacheability settings.
  • Anders
    Anders about 10 years
    @CertifiedCrazy - feel free to add them in; I'm sure this answer from 6 years ago is a bit stale now.