1

I thought using a meta tag like:

<meta http-equiv="Pragma" CONTENT="no-cache">

would automatically refresh my page according to https://web.archive.org/web/20210927201700/http://www.4guysfromrolla.com/webtech/111500-1.shtml

however my page is not refreshing!

What I am doing is dynamically loading checkboxes onto the screen from a database table that has an active column whether to initially have it checked, and furthermore an onclick event handler that takes action client side (shows in another div tag only the active ones). When I click a submit button the action directs to another (classic) asp page and saves the changes (active state) server side however, when I click the Back Button in my browser the server side code must be called as the dynamic setup of the checkboxes has the correct state however my client side that is called when I toggle the checkbox is not the same value as I left it rather the value when the page was first loaded so I thought to automatically refresh the page was the way to go by having no cache. I guess this is not IE friendly or I am doing something wrong.

Please do not ask for the URL as it is an internal website. How much of the code do you need me to send you?

The screen shot below has a non hover and hover state joined as one picture after I click the back button. To explain the situation, the top image shows only one active recipient. The bottom image shows 2. The process is: I select another recipient after initially having only one. I click a submit button. It saves the second recipient to the database. I click the Back button on my browser. The active recipients list still shows only one user. If I enter into edit mode (hover over my green label) it shows 2 recipients.

How can this be? Both active only (non-hover) and full list are loaded server side!

enter image description here

Glen
  • 802
  • 1
  • 11
  • 27
  • 1
    Try this it worked for me in a similar situation – Dave Norm Jun 07 '16 at 03:58
  • Tried it still does not refresh only if I physically click the refresh does it render correctly – Glen Jun 07 '16 at 04:22
  • try body with nothing in the quotes – Dave Norm Jun 07 '16 at 04:26
  • This did not work either – Glen Jun 07 '16 at 05:11
  • @DaveNorm `document.refresh();` is depreciated you should be using `window.location.reload(true);` now. The only reference to it is the [Internet Explorer WebBrowserControl](https://msdn.microsoft.com/en-us/library/aa752098(v=vs.85).aspx). Any modern browser will return `Object doesn't support property or method 'refresh'` including IE Edge. – user692942 Jun 07 '16 at 09:33

2 Answers2

0

I read thru a lot of posts here on stack overflow on the similar topic that talked about detecting the back button, I didn't particular want to make it complicated well for a first timer to this code it looked complicated however, then I was reminded of the fact @DaveNorm mentioned calling document.refresh() so I decided to call my own client-side function that actually does the work to update the active state in the onload event and it worked, so I will go with that.

Glen
  • 802
  • 1
  • 11
  • 27
  • While `document.refresh();` may work in older IE browsers you will have problems moving forward, I've explained why [here](http://stackoverflow.com/questions/37669796/site-not-refreshing-after-using-back-button/37675183#comment62828408_37669796). – user692942 Jun 07 '16 at 09:36
0

That line will not auto refresh your page it just stops the Internet Browser from caching the contents which should force it to request the latest version of the page from the web server.

Personally I'm not a fan of using client side tags to handle caching, prefer to set the headers server-side using a function like this that I can call at the top of the ASP page.

<%
Sub no_cache()
  Dim Str: Str = "private, no-cache, must-revalidate" 
  Response.ExpiresAbsolute = DateAdd("yyyy", -5, Date())
  Response.AddHeader "pragma", "no-cache" 
  Response.AddHeader "cache-control", Str
End Sub
%>

Then I can call it from an #include using one line in any page I don't want to be cached by the Internet Browser.

<%
Call no_cache()
%>

  • How to reload a page using Javascript? - This should help with the client-side refresh, ideally you want to use window.location.reload(true); to a force a refresh without using the client-side cache.
Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175