Firefox doesn't refresh image on UpdatePanel refresh.

Last post 10-14-2007 10:44 AM by altertoby. 5 replies.

Sort Posts:

  • Firefox doesn't refresh image on UpdatePanel refresh.

    01-11-2007, 1:48 AM

    Hi All,

     I know this will seem silly, but here is my predicament.  I have an updatepanel on the page surrounding an asp:image control.  It is essentially a User's profile picture.  There is a link next to the picture to allow the user to change their picture.  It opens a popup with a fileuploadcontrol in it and allows the user to select the image they would like to use.  After scaling it down, it stores the image in a database.  Then the popup closes and it turns javascript to only refresh the updatepanel on the main page. 

     All image downloads run through a custom httphandler that write out the bytes for the image (stored in the DB) and assigns that value to the ImageURL property of the asp:image control. 

    In IE v6.xxx, when the update panel refreshes, the image does as well.  However, in Firefox it does not.  I know that the updatepanel is indeed posting back, but the browser is not requesting the image again from the httphandler.

     Is there any way to force an image not to be cached in Firefox?  I know that this is considered a feature and in most scenarios I would agree - but this is one situation where I *need* the browser to request the image again.

    I haven't tested this in IE 7 yet - what type of behavior can I expect?

    I'd really like to avoid an entire page refresh just to refresh an image if I can help it. 

    Thoughts?  Suggestions?

     Thanks,
    Greg Varveris

    Filed under: , ,
  • Re: Firefox doesn't refresh image on UpdatePanel refresh.

    01-11-2007, 10:46 AM
    • Loading...
    • Rama Krishna
    • Joined on 01-24-2006, 9:33 PM
    • Atlanta, GA
    • Posts 307
    The way I solved this problem was to append a fake query string parameter to the URL which autoincremented each time. For example if the URL is image.ashx. If the image is updated I generate a new URL image.ashx?id=1. Not very elegant but it works.
  • Re: Firefox doesn't refresh image on UpdatePanel refresh.

    01-11-2007, 3:15 PM

    Rama,

     Thank you for your response.  I ended up going with about the same.  During each page load, I append a non-sensical random number querystring value to the end of the link.  It's certainly not elegant. 

     Appearantly, though, you can set the cacheability of a page using the following command:

    Response.Cache.SetCacheability(HttpCacheability.NoCache)

    The places where I saw it used was to make sure that a user couldn't click the 'Back' button on their browser after logging out of a site.  I attempted to do the same thing in my httphandler, but it didn't work, although I'm not certain why it didn't.

     At least this is a ready workaround until I figure out the more elegant and focused solution, me-thinks.

     Thank you for the input.

    Sincerely,
    Greg Varveris

  • Re: Firefox doesn't refresh image on UpdatePanel refresh.

    01-12-2007, 9:02 AM
    • Loading...
    • stmarti
    • Joined on 06-06-2006, 12:20 PM
    • Posts 699

    Hi,

    You can check some advanced cache settings in firefox. Maybe you can figure out the difference between firefox and ie image caching.

    Using about:config in firefox. I would start here.

  • Re: Firefox doesn't refresh image on UpdatePanel refresh.

    02-27-2007, 6:57 PM
    • Loading...
    • mikebridge
    • Joined on 10-03-2006, 5:02 PM
    • Edmonton, Canada
    • Posts 25

    Did anyone find the ultimate reason for this?  I have an UpdatePanel which contains a 3rd-party control which displays an image via an HttpHandler.  The control produces a url which renders an image, but I don't have any control over this URL from C#, so I can't append a random string on the end.  I can update the control to render a new image, but the image doesn't get refreshed in Firefox or IE until I refresh the cache manually.  Setting "NoCache" doesn't seem to help.

     Thanks,

     -Mike


     

  • Re: Firefox doesn't refresh image on UpdatePanel refresh.

    10-14-2007, 10:44 AM
    • Loading...
    • altertoby
    • Joined on 03-16-2007, 11:45 AM
    • Posts 4
    < script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(pageLoaded);
    var c = 0;
    function pageLoaded(sender, args)
    {
    var img = document.getElementById("Control");
    c++;
    img.src = img.src + "?" + c;
    }
    
    and replace "Control" with the name of your control. For me it works.
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter