Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • Last Modified:

Image not changed after update

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
Balshe
Asked:
Balshe
  • 3
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
RouchieCommented:
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
 
RouchieCommented:
Must type faster... :-|
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BalsheAuthor Commented:
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
 
BalsheAuthor Commented:
thank s alot ..you solved my problem.
0
 
RouchieCommented:
Great!  

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now