GotKnowHow.com

How to Refresh an Image in ASP.NET Automatically

by


You may need to have an image refreshed automatically on a web page in ASP.NET to get the latest image.  One instance where you might want the fresh image is if you upload an image that has the same file name as an already existing image file on the server, and when the page is Redirected or reloaded, you still see the old image, since it is cached. 

To get the latest image file in ASP.NET you can simply add a querystring to the end of the image file name that changes.  An easy way to do this is to just add the current DateTime to a querystring.  For example:

StoreLogoImage.ImageUrl = "~/someImage.jpg?refreshTime=" + Server.UrlEncode(DateTime.Now.TimeOfDay.ToString());

Because the file name with the TimeOfDay querystring will be different each time the page is refreshed, the latest image will be retrieved, instead of the cached image.

 


0
0

Add your comment

by Anonymous - Already have an account? Login now!
Your Name:  

Comment:  
Enter the text you see in the image below
What do you see?
Can't read the image? View a new one.
Your comment will appear after being approved.


Did this article help you out, share it with your friends:

Ask a Question

140 characters left

Recent Articles