By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

Reload a page when back button pressed

P: n/a
Rob
I know this is an old one, considering how many posts I found on it but I
just wondered if any best practises had popped up recently, especially as
Ajax has increased JavaScript and DHTML's importance.

I'm writing a database application. I like pop-up boxes so I've implemented
one on my webpage using a floating DIV. The logic goes like this:

1. When the page is rendered (on the server), it adds "var DisplayPopup =
false;" in the page
2. A JavaScript function in the page checks this variable and sets the style
of the popup DIV to hidden or visible as required
3. The user bashes in some data and hits the SAVE button
4. Postback occurs and validates the form. If there is an problem, the text
inside the HTML is updated with the validation message
5. When the page renders (on the server) this time, it adds "var
DisplayPopup = true;" in the page
6. Same JavaScript function as above notices this and sets the style to
visible

On the popup there is an OK button which simply triggers another JavaScript
function to set the style back to hidden.

Works a treat - most of the time!!

It fails if the user goes to another page (say a static HTML page) and then
presses the back button.

The browser (IE7 in this case) retrieves the page from the cache. This
cached page has "var DisplayPopup = true;" in there so when the JavaScript
runs again, it displays the popup.

All I want to be able to do is *somehow* instruct the browser that it should
never get this page back from the cache, but should always get it from the
server. Now I think there are a collection of various page expiry settings
that might help here but I wondered if these also prevent resources from
within the page from also caching? I don't want this to happen - just reload
the ASPX page itself. I don't want it to not cache images etc.

It would be really neat if there was some JavaScript way of persisting
variables in the cache. I know about cookies but don't particularly want to
have to use those for this simple requirement.

Thanks, Rob.
Oct 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
you set your page to expire (so it can not be pulled from the cache).
also if you look at google's web tool kit's browser history management
object, to see what others are doing.
those that have not yet looked at google web toolkit should. instead of
being server based spewing javascript, its browser based with ajax calls
to the server. this means all the controls are client based with client
script apis and properties.

they also have a java to javascript compiler that is also interesting.
-- bruce (sqlwork.com)

Rob wrote:
I know this is an old one, considering how many posts I found on it but I
just wondered if any best practises had popped up recently, especially as
Ajax has increased JavaScript and DHTML's importance.

I'm writing a database application. I like pop-up boxes so I've implemented
one on my webpage using a floating DIV. The logic goes like this:

1. When the page is rendered (on the server), it adds "var DisplayPopup =
false;" in the page
2. A JavaScript function in the page checks this variable and sets the style
of the popup DIV to hidden or visible as required
3. The user bashes in some data and hits the SAVE button
4. Postback occurs and validates the form. If there is an problem, the text
inside the HTML is updated with the validation message
5. When the page renders (on the server) this time, it adds "var
DisplayPopup = true;" in the page
6. Same JavaScript function as above notices this and sets the style to
visible

On the popup there is an OK button which simply triggers another JavaScript
function to set the style back to hidden.

Works a treat - most of the time!!

It fails if the user goes to another page (say a static HTML page) and then
presses the back button.

The browser (IE7 in this case) retrieves the page from the cache. This
cached page has "var DisplayPopup = true;" in there so when the JavaScript
runs again, it displays the popup.

All I want to be able to do is *somehow* instruct the browser that it should
never get this page back from the cache, but should always get it from the
server. Now I think there are a collection of various page expiry settings
that might help here but I wondered if these also prevent resources from
within the page from also caching? I don't want this to happen - just reload
the ASPX page itself. I don't want it to not cache images etc.

It would be really neat if there was some JavaScript way of persisting
variables in the cache. I know about cookies but don't particularly want to
have to use those for this simple requirement.

Thanks, Rob.

Oct 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.