Image Control not refreshing

M

Mark Denardo

I created a Web Image "<asp:Image ID="Image1" ..." that my code behind set
to a certain image file say image1.jpg

=> Image1.ImageUrl = "<rel_path>/image1.jpg";

which set the image ok, but then I replaced that image file with another
image file and gave it the same name "image1.jpg". But my web app when it
loads the image when I run the page still shows the original picture that I
deleted and replaced with the new one, even though I restarted the entire
app. I'm thinking that the image is cached in some way and needs to be
refreshed somehow, so I tried adding the following:

=> Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
=> Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)

These are called by button clicks so I can see the results dynamically. And
what I see is when I click button2, that image shows the second image
correctly, and when I click button1, it again shows the old image I deleted
over a day ago.

How do I make my page refresh or flush that image?? (I've started and
stopped the app. a dozen times over the past day and a half and it still has
the old photo I deleted lingering in memory somewhere and doesn't want to
let it go.)
 
M

Mark E. Hansen

I created a Web Image "<asp:Image ID="Image1" ..." that my code behind set
to a certain image file say image1.jpg

=> Image1.ImageUrl = "<rel_path>/image1.jpg";

which set the image ok, but then I replaced that image file with another
image file and gave it the same name "image1.jpg". But my web app when it
loads the image when I run the page still shows the original picture that I
deleted and replaced with the new one, even though I restarted the entire
app. I'm thinking that the image is cached in some way and needs to be
refreshed somehow, so I tried adding the following:

=> Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
=> Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)

These are called by button clicks so I can see the results dynamically. And
what I see is when I click button2, that image shows the second image
correctly, and when I click button1, it again shows the old image I deleted
over a day ago.

How do I make my page refresh or flush that image?? (I've started and
stopped the app. a dozen times over the past day and a half and it still has
the old photo I deleted lingering in memory somewhere and doesn't want to
let it go.)

I don't think it's the application - it's the browser. Try clearing your
browser cache and see what it displays then.
 
M

Mark Denardo

Mark E. Hansen said:
I don't think it's the application - it's the browser. Try clearing your
browser cache and see what it displays then.

How do I clear the cache? I'm running the app out of VS2005. When I stop
the app, the browser shuts down, shouldn't that clear any cache?
 
M

Mark Denardo

Mark E. Hansen said:
I don't think it's the application - it's the browser. Try clearing your
browser cache and see what it displays then.

Mark, I figured out how to clear the cache and this solved the problem.
(although this now raises another problem, but I'll have to think about it)

Thanks
 
M

Mark E. Hansen

How do I clear the cache? I'm running the app out of VS2005. When I stop
the app, the browser shuts down, shouldn't that clear any cache?

Closing the browser does not clear its cache (but this is up to the
browser). Each browser has its own mechanism for doing this. Knowing
which browser you're using may help - but have a look at the browser
settings - you may be able to find it on your own.

Keep in mind that the content (an image in this case) will be sent to
your client (usually a browser) with an expiration date/time. The client
is welcome to cache the content until it expires, at which time it should
clear the content from its cache.

Once you get clear on this, your next question will be "how do I set the
expiration on my image..." ;-)

Before you do this, consider the consequences. For example, caching the
image really improves performance. If the image doesn't change very often,
it's probably much better if you let the client cache it. If, on the other
hand, your image is expected to change all the time (like a graph of a stock
value) then you probably need it to expire in relatively short order, like
within just a few minutes.

As to how to get your application to specify the expiration you want for
a particular image, I don't know - I'll leave that for someone else to
answer.

Hope this helps,
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Mark said:
Mark, I figured out how to clear the cache and this solved the problem.
(although this now raises another problem, but I'll have to think about it)

Thanks

You can add a version counter to the url:

Image1.ImageUrl = "<rel_path>/image1.jpg?v=" + version.ToString();

The argument will of course be ignored by the server when the image is
requested, but it makes the url unique for each version.
 
M

Mark Denardo

The versioning worked, thanks.

Göran Andersson said:
You can add a version counter to the url:

Image1.ImageUrl = "<rel_path>/image1.jpg?v=" + version.ToString();

The argument will of course be ignored by the server when the image is
requested, but it makes the url unique for each version.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top