Solved

Image not changed after update

Posted on 2010-11-11
6
859 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 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