Re: How do I update an image without manual refresh?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The browser will think it is a different image and will get it from the
server.

It doesn't have to be in javascript. If you do it on server side, you can
use the Random class for generating random numbers and adding them to the
image url.

imgControl.ImageUrl = "http://imagePath.jpg?"; +
myFunctionThatGetsRandomString();

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


"Jerry J" <JerryJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5D1EC8DA-B7BB-423C-B9E9-436C84A36F4B@xxxxxxxxxxxxxxxx
Eliyahu,

Not sure what you mean here? What happens when the client executes that
JAVA
script?

--
Jerry J


"Eliyahu Goldin" wrote:

You can trick the browser into getting the image from the server rather
than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMilliseconds();

}


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


"Jerry J" <JerryJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3251161D-A7D0-4FBE-8BC0-26B7790B051A@xxxxxxxxxxxxxxxx

How can I get an asp:Image to refresh when a user uploads a different
jpg.

I disabled caching using this command on Page_Load():
Response.Cache.SetCacheability(HttpCacheability.No Cache);
but it didn't help.


The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.


The code to change the image is this simple: imgControl.ImageUrl =
"http://imagePath.jpg";;

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a
refresh,
wouldn't it still use the image from the cache?


--
Jerry J





.



Relevant Pages

  • Re: datatel envision
    ... to generate custome javascript calls ... to run BASIC code from the browser; tools that don't require you to ... BASIC is the best language for server ... is confusing...the developer must've setup the resolution between ...
    (comp.databases.pick)
  • comp.lang.javascript FAQ - Quick Answers 2008-10-13
    ... Javascript Tips ... _How can I disable the back button in a web browser_? ... _How do I check to see if a child window is open, ... upon the cache headers that your server sends. ...
    (comp.lang.javascript)
  • Re: Client side changes not reflected in page
    ... time you request a page from the browser, asp.net generates a HTML document ... that is sent back and parsed by the browser. ... document on the client side via JavaScript / VBScript. ... the server side, or use AJAX asynchronous calls. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Code added to my XHTML source files giving problems
    ... Server: webserver ... Get a proper web browser and developer tools, ... it's not powered by the Google logo... ... Mozilla throws a javascript error when fed with an HTML ...
    (comp.infosystems.www.authoring.html)
  • Re: Re: scary site
    ... display it back to the browser only. ... back to the server. ... you could then use another javascript include file on another server ... but not transmit that info back to the server. ...
    (Security-Basics)