Monday, February 27, 2006

 

asp.net c# Image Control doesn't update (fix)

When writing asp.net c# pages, you might notice that the image control will not refresh when pointing to an image on the server. The control itself will refresh the image if the file name changes, but if the picture changes (and not the filename) then you'll always be stuck with the same old image.

I found a fix for this and wanted to post it (since it's not so easy to find).

By passing a dynamic parameter to the back of the image URL, you'll trick the control into thinking the filename has changed. Magically the control will start working as expected.

So if you code was:

oImage.ImageURL = "/images/picture.jpg";

change it to:

oImage.ImageURL = "/images/picture.jpg?" + System.DateTime.Now.ToString();


If you enjoyed this article Subscribe to my RSS Feed
 Post to Del.icio.us Account Bookmark this page on del.icio.us
|



<< Home

This page is powered by Blogger. Isn't yours?