views:

2442

answers:

5

Hi all,

I have an ASPX page where I am uploading an image to server for on a serverside button click event. In my page, it will show the available image if it exists. When I upload an image, it will replace the old one with the new one. Now after uploading also the same image is getting displayed. How can tackle this? I used window.location.reload() javascript function to refresh, but then it is not working. It is posting the page again.

This is my code

    Do UploadImage(studentId,mode);  // Function to upload image
    StringBuilder sbc = new StringBuilder();

    sbc.Append("<script language='javascript'>");
    sbc.Append("alert('Upload process completed successfully!');");
    sbc.Append("window.location.reload()");
    sbc.Append("</script>");
    HttpContext.Current.Response.Write(sbc);
+2  A: 

Your browser is probably caching the image. Either disable caching on the image or set up proper caching responses.

strager
A: 

You can reload from the server side

Response.Redirect(Request.URL)
LeJeune
I am getting Can not redirect after HTTP headers have been sent Message
Shyju
You can refer to this thread - <http://stackoverflow.com/questions/159523/why-do-i-get-cannot-redirect-after-http-headers-have-been-sent-when-i-call-resp>
LeJeune
A: 

I am getting Can not redirect after HTTP headers have been sent Message

Shyju
This should be a comment, not an answer.
Geoffrey Chetwood
+2  A: 

It's being cached in the browser. To overcome this - alter the url of the image. This can be done by including a timestamp, version number, or guid in the image file name.

GeekyMonkey
A: 

A useful tool to debug this is fiddler. As others already suggested it's likely that the browser caches the old version of the image. If you are using IIS you can change the cache policy so that the browser always check for a newer version of the image.

Cristian Libardo