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

Force browser to refresh?

P: n/a
I have a page that displays a picture. In the page load I figure out which
image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but the
old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new image?

Thanks,
---Selden McCabe
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
To prevent caching, use this code:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Selden McCabe" <se*****@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a page that displays a picture. In the page load I figure out which
image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but the
old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new image?

Thanks,
---Selden McCabe

Nov 19 '05 #2

P: n/a
I tried putting this in the page_load event, but it didn't have any effect.
When I do back, select a different student, then click view, I see the old
one
until I click the browser's refresh.

Where should I put this code?

Thanks!
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
To prevent caching, use this code:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Selden McCabe" <se*****@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a page that displays a picture. In the page load I figure out
which image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but the
old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new image?

Thanks,
---Selden McCabe


Nov 19 '05 #3

P: n/a
One trick is to use a QueryString in the image tag, with some differing
value each time the image is displayed. It doesn't affect the image, but
fools the browser into thinking it is downloading a different resource.
Example:

<img src="someimage.jpg?q=1">
<img src="someimage.jpg?q=2">
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Selden McCabe" <se*****@msn.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
I have a page that displays a picture. In the page load I figure out which image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but the
old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new image?

Thanks,
---Selden McCabe

Nov 19 '05 #4

P: n/a
Page_Load is fine.
You should manually clear your browser cache, because it's likely still in
your cache from before you put the code in.
I'm assuming you're pointing to a standard image file like a jpg or gif.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"Selden McCabe" <se*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I tried putting this in the page_load event, but it didn't have any effect.
When I do back, select a different student, then click view, I see the old
one
until I click the browser's refresh.

Where should I put this code?

Thanks!
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
To prevent caching, use this code:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Selden McCabe" <se*****@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a page that displays a picture. In the page load I figure out
which image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but
the old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new
image?

Thanks,
---Selden McCabe



Nov 19 '05 #5

P: n/a
Thank you, Kevin!

Somehow I forgot that I was always using "images\temp.jpeg" for the file
name,
so of course the browser didn't know I was changing the image each time.

Once I got your suggestion, I changed it to:
"images\temp.jpeg?current=" + DateTime.Now

and it's working fine.

Thanks for the help!!!!
---Selden
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:OO**************@TK2MSFTNGP14.phx.gbl...
One trick is to use a QueryString in the image tag, with some differing
value each time the image is displayed. It doesn't affect the image, but
fools the browser into thinking it is downloading a different resource.
Example:

<img src="someimage.jpg?q=1">
<img src="someimage.jpg?q=2">
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Selden McCabe" <se*****@msn.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
I have a page that displays a picture. In the page load I figure out

which
image and then do a StudentPicutre.imageurl = <some file name>

But if you use the browser's back button, enter different criteria, then
click the view button, the code runs to load a different picture, but the
old one shows up until I hit the browser's refresh button.

What am I doing wrong? How do I force the browser to load the new image?

Thanks,
---Selden McCabe


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.