Solved

Image not changed after update

Posted on 2010-11-11
6
854 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

11 Experts available now in Live!

Get 1:1 Help Now