Solved

Image not changed after update

Posted on 2010-11-11
6
858 Views
Last Modified: 2013-11-05
Hi,

My web application is asp.net +vb.net with master page,the problem is when i change the image in a certain page with another one but with the same ImageUrl I don't get the updated image, instead i keep getting the old image,only when i delete the history,temp and data of the browser (IE) from Tools\Internet Option\..) or after some time I get the updated image.

this is my code:

 Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand


  If e.CommandName.ToLower() = "viewd" Then
           
            Dim lb As LinkButton = CType(e.CommandSource, LinkButton)
            Dim gvRow As GridViewRow = lb.BindingContainer 'Getting current row to get index
            Dim strKey As String = GridView1.DataKeys(gvRow.RowIndex)(0).ToString()        
            Dim NewsBody As TextBox = CType(gvRow.Cells(1).FindControl("NewsBody"), TextBox)
            PopPanel.Visible = True          
            Image1.ImageUrl = "~/NewsImages/Images/" + strKey + ".jpg"
            details.Text = NewsBody.Text

end if
end sub


Appreciate your help.

0
Comment
Question by:Balshe
  • 3
  • 2
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34109662
The problem is that the client browser will be caching the image. Try adding the following to your page:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 34109675
Hi there.  This is a common problem caused by the browser caching the file.  The browser obviously sees the same URL for the image and just uses a cached version.  To prevent this happening, there are two approaches:

1) You can stop the pages caching by adding this in the Page_Load:

               Response.Cache.SetCacheability(HttpCacheability.NoCache)

Beware however that the browser will stop caching EVERYTHING, so your data usage will increase as all page elements will be reloaded each time.

2)  You can append a fake querystring to the ImageUrl, tricking the browser into thinking its a different image.  e.g.

    Dim rand as new Random()
    myImage.ImageUrl = "~/images/myimage.jpg?" & rand.Next(0, 10000)

which will create something like this:   /images/myimage.jpg?5412
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 34109676
Must type faster... :-|
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Balshe
ID: 34109692
Dear,
I know this is a client caching issue,and the above code is not help me.so what should I do???!!.
thank you.
0
 
LVL 1

Author Comment

by:Balshe
ID: 34109713
thank s alot ..you solved my problem.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 34110061
Great!  

...(don't forget to close the question! :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now