Image Control not refreshing

Discussion in 'ASP .Net' started by Mark Denardo, Oct 20, 2006.

  1. Mark Denardo

    Mark Denardo Guest

    I created a Web Image "<asp:Image ID="Image1" ..." that my code behind set
    to a certain image file say image1.jpg

    => Image1.ImageUrl = "<rel_path>/image1.jpg";

    which set the image ok, but then I replaced that image file with another
    image file and gave it the same name "image1.jpg". But my web app when it
    loads the image when I run the page still shows the original picture that I
    deleted and replaced with the new one, even though I restarted the entire
    app. I'm thinking that the image is cached in some way and needs to be
    refreshed somehow, so I tried adding the following:

    => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)

    These are called by button clicks so I can see the results dynamically. And
    what I see is when I click button2, that image shows the second image
    correctly, and when I click button1, it again shows the old image I deleted
    over a day ago.

    How do I make my page refresh or flush that image?? (I've started and
    stopped the app. a dozen times over the past day and a half and it still has
    the old photo I deleted lingering in memory somewhere and doesn't want to
    let it go.)
     
    Mark Denardo, Oct 20, 2006
    #1
    1. Advertising

  2. On 10/20/06 10:04, Mark Denardo wrote:
    > I created a Web Image "<asp:Image ID="Image1" ..." that my code behind set
    > to a certain image file say image1.jpg
    >
    > => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >
    > which set the image ok, but then I replaced that image file with another
    > image file and gave it the same name "image1.jpg". But my web app when it
    > loads the image when I run the page still shows the original picture that I
    > deleted and replaced with the new one, even though I restarted the entire
    > app. I'm thinking that the image is cached in some way and needs to be
    > refreshed somehow, so I tried adding the following:
    >
    > => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    > => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >
    > These are called by button clicks so I can see the results dynamically. And
    > what I see is when I click button2, that image shows the second image
    > correctly, and when I click button1, it again shows the old image I deleted
    > over a day ago.
    >
    > How do I make my page refresh or flush that image?? (I've started and
    > stopped the app. a dozen times over the past day and a half and it still has
    > the old photo I deleted lingering in memory somewhere and doesn't want to
    > let it go.)
    >
    >


    I don't think it's the application - it's the browser. Try clearing your
    browser cache and see what it displays then.
     
    Mark E. Hansen, Oct 20, 2006
    #2
    1. Advertising

  3. Mark Denardo

    Mark Denardo Guest

    "Mark E. Hansen" <> wrote in message
    news:...
    > On 10/20/06 10:04, Mark Denardo wrote:
    >> I created a Web Image "<asp:Image ID="Image1" ..." that my code behind
    >> set
    >> to a certain image file say image1.jpg
    >>
    >> => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >>
    >> which set the image ok, but then I replaced that image file with another
    >> image file and gave it the same name "image1.jpg". But my web app when
    >> it
    >> loads the image when I run the page still shows the original picture that
    >> I
    >> deleted and replaced with the new one, even though I restarted the entire
    >> app. I'm thinking that the image is cached in some way and needs to be
    >> refreshed somehow, so I tried adding the following:
    >>
    >> => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    >> => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >>
    >> These are called by button clicks so I can see the results dynamically.
    >> And
    >> what I see is when I click button2, that image shows the second image
    >> correctly, and when I click button1, it again shows the old image I
    >> deleted
    >> over a day ago.
    >>
    >> How do I make my page refresh or flush that image?? (I've started and
    >> stopped the app. a dozen times over the past day and a half and it still
    >> has
    >> the old photo I deleted lingering in memory somewhere and doesn't want to
    >> let it go.)
    >>
    >>

    >
    > I don't think it's the application - it's the browser. Try clearing your
    > browser cache and see what it displays then.


    How do I clear the cache? I'm running the app out of VS2005. When I stop
    the app, the browser shuts down, shouldn't that clear any cache?
     
    Mark Denardo, Oct 20, 2006
    #3
  4. Mark Denardo

    Mark Denardo Guest

    "Mark E. Hansen" <> wrote in message
    news:...
    > On 10/20/06 10:04, Mark Denardo wrote:
    >> I created a Web Image "<asp:Image ID="Image1" ..." that my code behind
    >> set
    >> to a certain image file say image1.jpg
    >>
    >> => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >>
    >> which set the image ok, but then I replaced that image file with another
    >> image file and gave it the same name "image1.jpg". But my web app when
    >> it
    >> loads the image when I run the page still shows the original picture that
    >> I
    >> deleted and replaced with the new one, even though I restarted the entire
    >> app. I'm thinking that the image is cached in some way and needs to be
    >> refreshed somehow, so I tried adding the following:
    >>
    >> => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    >> => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >>
    >> These are called by button clicks so I can see the results dynamically.
    >> And
    >> what I see is when I click button2, that image shows the second image
    >> correctly, and when I click button1, it again shows the old image I
    >> deleted
    >> over a day ago.
    >>
    >> How do I make my page refresh or flush that image?? (I've started and
    >> stopped the app. a dozen times over the past day and a half and it still
    >> has
    >> the old photo I deleted lingering in memory somewhere and doesn't want to
    >> let it go.)
    >>
    >>

    >
    > I don't think it's the application - it's the browser. Try clearing your
    > browser cache and see what it displays then.


    Mark, I figured out how to clear the cache and this solved the problem.
    (although this now raises another problem, but I'll have to think about it)

    Thanks
     
    Mark Denardo, Oct 20, 2006
    #4
  5. On 10/20/06 10:35, Mark Denardo wrote:
    > "Mark E. Hansen" <> wrote in message
    > news:...
    >> On 10/20/06 10:04, Mark Denardo wrote:
    >>> I created a Web Image "<asp:Image ID="Image1" ..." that my code behind
    >>> set
    >>> to a certain image file say image1.jpg
    >>>
    >>> => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >>>
    >>> which set the image ok, but then I replaced that image file with another
    >>> image file and gave it the same name "image1.jpg". But my web app when
    >>> it
    >>> loads the image when I run the page still shows the original picture that
    >>> I
    >>> deleted and replaced with the new one, even though I restarted the entire
    >>> app. I'm thinking that the image is cached in some way and needs to be
    >>> refreshed somehow, so I tried adding the following:
    >>>
    >>> => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    >>> => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >>>
    >>> These are called by button clicks so I can see the results dynamically.
    >>> And
    >>> what I see is when I click button2, that image shows the second image
    >>> correctly, and when I click button1, it again shows the old image I
    >>> deleted
    >>> over a day ago.
    >>>
    >>> How do I make my page refresh or flush that image?? (I've started and
    >>> stopped the app. a dozen times over the past day and a half and it still
    >>> has
    >>> the old photo I deleted lingering in memory somewhere and doesn't want to
    >>> let it go.)
    >>>
    >>>

    >>
    >> I don't think it's the application - it's the browser. Try clearing your
    >> browser cache and see what it displays then.

    >
    > How do I clear the cache? I'm running the app out of VS2005. When I stop
    > the app, the browser shuts down, shouldn't that clear any cache?
    >
    >


    Closing the browser does not clear its cache (but this is up to the
    browser). Each browser has its own mechanism for doing this. Knowing
    which browser you're using may help - but have a look at the browser
    settings - you may be able to find it on your own.

    Keep in mind that the content (an image in this case) will be sent to
    your client (usually a browser) with an expiration date/time. The client
    is welcome to cache the content until it expires, at which time it should
    clear the content from its cache.

    Once you get clear on this, your next question will be "how do I set the
    expiration on my image..." ;-)

    Before you do this, consider the consequences. For example, caching the
    image really improves performance. If the image doesn't change very often,
    it's probably much better if you let the client cache it. If, on the other
    hand, your image is expected to change all the time (like a graph of a stock
    value) then you probably need it to expire in relatively short order, like
    within just a few minutes.

    As to how to get your application to specify the expiration you want for
    a particular image, I don't know - I'll leave that for someone else to
    answer.

    Hope this helps,
     
    Mark E. Hansen, Oct 20, 2006
    #5
  6. Mark Denardo wrote:
    > "Mark E. Hansen" <> wrote in message
    > news:...
    >> On 10/20/06 10:04, Mark Denardo wrote:
    >>> I created a Web Image "<asp:Image ID="Image1" ..." that my code behind
    >>> set
    >>> to a certain image file say image1.jpg
    >>>
    >>> => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >>>
    >>> which set the image ok, but then I replaced that image file with another
    >>> image file and gave it the same name "image1.jpg". But my web app when
    >>> it
    >>> loads the image when I run the page still shows the original picture that
    >>> I
    >>> deleted and replaced with the new one, even though I restarted the entire
    >>> app. I'm thinking that the image is cached in some way and needs to be
    >>> refreshed somehow, so I tried adding the following:
    >>>
    >>> => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    >>> => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >>>
    >>> These are called by button clicks so I can see the results dynamically.
    >>> And
    >>> what I see is when I click button2, that image shows the second image
    >>> correctly, and when I click button1, it again shows the old image I
    >>> deleted
    >>> over a day ago.
    >>>
    >>> How do I make my page refresh or flush that image?? (I've started and
    >>> stopped the app. a dozen times over the past day and a half and it still
    >>> has
    >>> the old photo I deleted lingering in memory somewhere and doesn't want to
    >>> let it go.)
    >>>
    >>>

    >> I don't think it's the application - it's the browser. Try clearing your
    >> browser cache and see what it displays then.

    >
    > Mark, I figured out how to clear the cache and this solved the problem.
    > (although this now raises another problem, but I'll have to think about it)
    >
    > Thanks
    >
    >


    You can add a version counter to the url:

    Image1.ImageUrl = "<rel_path>/image1.jpg?v=" + version.ToString();

    The argument will of course be ignored by the server when the image is
    requested, but it makes the url unique for each version.
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Oct 21, 2006
    #6
  7. Mark Denardo

    Mark Denardo Guest

    The versioning worked, thanks.

    "Göran Andersson" <> wrote in message
    news:%...
    > Mark Denardo wrote:
    >> "Mark E. Hansen" <> wrote in message
    >> news:...
    >>> On 10/20/06 10:04, Mark Denardo wrote:
    >>>> I created a Web Image "<asp:Image ID="Image1" ..." that my code behind
    >>>> set
    >>>> to a certain image file say image1.jpg
    >>>>
    >>>> => Image1.ImageUrl = "<rel_path>/image1.jpg";
    >>>>
    >>>> which set the image ok, but then I replaced that image file with
    >>>> another
    >>>> image file and gave it the same name "image1.jpg". But my web app when
    >>>> it
    >>>> loads the image when I run the page still shows the original picture
    >>>> that I
    >>>> deleted and replaced with the new one, even though I restarted the
    >>>> entire
    >>>> app. I'm thinking that the image is cached in some way and needs to be
    >>>> refreshed somehow, so I tried adding the following:
    >>>>
    >>>> => Image1.ImageUrl = "<rel_path>/image2.jpg"; (button click 2)
    >>>> => Image1.ImageUrl = "<rel_path>/image1.jpg"; (button click 1)
    >>>>
    >>>> These are called by button clicks so I can see the results dynamically.
    >>>> And
    >>>> what I see is when I click button2, that image shows the second image
    >>>> correctly, and when I click button1, it again shows the old image I
    >>>> deleted
    >>>> over a day ago.
    >>>>
    >>>> How do I make my page refresh or flush that image?? (I've started and
    >>>> stopped the app. a dozen times over the past day and a half and it
    >>>> still has
    >>>> the old photo I deleted lingering in memory somewhere and doesn't want
    >>>> to
    >>>> let it go.)
    >>>>
    >>>>
    >>> I don't think it's the application - it's the browser. Try clearing your
    >>> browser cache and see what it displays then.

    >>
    >> Mark, I figured out how to clear the cache and this solved the problem.
    >> (although this now raises another problem, but I'll have to think about
    >> it)
    >>
    >> Thanks
    >>
    >>

    >
    > You can add a version counter to the url:
    >
    > Image1.ImageUrl = "<rel_path>/image1.jpg?v=" + version.ToString();
    >
    > The argument will of course be ignored by the server when the image is
    > requested, but it makes the url unique for each version.
     
    Mark Denardo, Oct 22, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    433
    Bruce Barker
    Jul 28, 2005
  2. PeterKellner
    Replies:
    0
    Views:
    606
    PeterKellner
    Jun 1, 2006
  3. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    470
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  4. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    198
    Harlan Messinger
    Aug 3, 2006
  5. Dev
    Replies:
    1
    Views:
    130
    Erwin Moller
    Jan 26, 2009
Loading...

Share This Page