I was working on a uploading script in asp.net. In asp.net its straightforward & easy and also I am not writing on uploading issue. Its about image refresh. When I click upload, it causes a postback, uploads the selected image , but on page, it still remains the past image. To recover from this problem, you have to do a simple thing, wither from server site script or client site(javascript). In asp.net/c#, its as like follows:
imgLogo.Src = "~/pages/images/testLogo.gif?"+DateTime.Now.Second.ToString();
call this after the uploading script. For doing this in javascript, simply call a function on page load which will set the src attribute like as follow:
tmp = new Date();
imageUrl = "pages/images/testLogo.gif?"+tmp.getTime().toString();
document.getElementById('imgLogo').src = imageUrl;
You will always get updated image. This appended timestamp causes browser each time to load the image again rather than load from cache.
Subscribe to:
Post Comments (Atom)










0 comments:
Post a Comment