Force browser to refresh?

S

Selden McCabe

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
 
S

Steve C. Orr [MVP, MCSD]

To prevent caching, use this code:

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

Selden McCabe

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!
 
K

Kevin Spencer

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.
 
S

Steve C. Orr [MVP, MCSD]

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
 
S

Selden McCabe

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top