views:

426

answers:

5

How to inject JS code when browser's button is clicked? I noticed that RegisterStartupScript during that page life cycle doesn't inject any JS code.

OR

How to force any browser to not use the cache and do a fresh complete page load when back button is used?

A: 

you can check the Referring URL (through Request object or HTTP Server Variables) to see if it comes from the certain page in the Page Load event and then load your javascript from there.

Cody C
A: 

I think that depends on what you have that is being cached... for example, in a project I had IE caching images, and no matter if you pressed the back button or refresh the page, the image won't be refreshed. So the solution was to add a querystring to the img source with a timestamp.

Hope it helps.

Sebastian
A: 

Try adding the following line to the Page Load event. The page will not be cached and will be reloaded, not retreived from the cache.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Phaedrus
A: 

I think you want to set the HttpCachePolicy as follows:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
drs9222
A: 

You must use this code, this avoids the caching of the page and then page will load completely

Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1

or use this

<meta http-equiv="expires" content="-1" />
Muhammad Akhtar