PDA

View Full Version : [CLOSED] Force load of an image



rguardado
Jan 26, 2015, 12:21 AM
Hi, I hope you can help me.

I have this in my web page:

<ext:Panel runat="server" Width="410" Border="false" Layout="VBoxLayout">
<Items>
<ext:Image ID="iCa" runat="server" Width="380" Height="280" />
<ext:Image ID="iCr" runat="server" Width="380" Height="280"/>
</Items>
</ext:Panel>


So, in codebehind I assign the imageUrl property:

iCa.ImageUrl = somvalue + ".jpg";


My question is, how can I force to load the image each time I call my webpage?.

I have this situation I load the webpage the first time, and it shows the current image on the disk, but in some cases I need to change the image(keeping the same filename), so in this cases it is when I need to force an image load of the right file(physical not the one in the cache).

Thanks.

rguardado
Jan 26, 2015, 12:33 AM
I put this in the code and it's working:


iCr.ImageUrl = somevalue + "jpg?t=" + Dates.TimeStamp();

Dates.TimeStamp is a function for generate the seconds from the actual date.

Any other solution is welcomed.

Daniil
Jan 26, 2015, 7:42 AM
Hi @rguardado,

It is called a cache buster that you used and it is probably the only solution in your scenario.

A new value of parameter in the URL's query string "tells" a browser to re-request the image instead of loading it from cache. A cache buster parameter's value is supposed to be unique. If your Dates.TimeStamp() returns the amount of seconds starting from some specific date, then it should be always unique unless a few page requests happen within one second.

It is another possible cache buster:

DateTime.Now.Ticks