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);
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.