Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Image not changed after update

Posted on 2010-11-11
6
Medium Priority
?
866 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
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.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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