views:

95

answers:

2

A.) When i use code to delete lets say Image123.jpg in folder Pics and i upload another image and rename that image also Image123.jpg and place it into folder Pics for some reason the new image get's displayed but its using the dimensions of the Image i delete. Using a Repeater over here to display the image.................

B.) When i just copy and past say Image99.jpg into my Pics folder that all ready contain a Image99.jpg then of course it changes the original one. So for some reason it must get cached because when i run my page it is still shows the first Image. Using a normal Image control over here................

Why is it doing A and B........and how can i go around this.....Problem A it more important to me because i need to change the Images names when the User clicks on "Change Logo" button.

Thanks in advanced!!!

+2  A: 

The browser caches the images, so if you replace an image you have to change the url that requests the image to see the new image.

You can do this either by:

  1. Changing the name of the image itself.

  2. Add a querystring to the url, which you change.

If you add a version number to the url, e.g. images/Image123.jpg?version=42 and increase the version number when you replace the image, the browser will request the new image from the server as the browser caches the files based on the complete url, not just the file name.

Guffa
How would i do that in code - adding version numbers that is.
Etienne
That depends on what your code looks like... how do you set the url of the image in the first place?
Guffa
+1  A: 

If it is indeed a caching issue you could do the following.

Programmatically:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Declaratively:

<%@ OutputCache Location="None" VaryByParam="None" %>

By caching Web pages, you avoid re-creating information on subsequent requests so keep in mind that this may adversely affect page load times as caching will be disabled.

Phaedrus
MMM, thanks, that could work i guess but i dont want to do that since the site is meant for South Africa and the internet is VERY slow over here!
Etienne