views:

436

answers:

2

hi i am using .ashx to retrive image and i place the the image inside the ajax update panel it retrive the image when a new image is added to the form but when we change the image it is not updating the image it dont even call the .ashx file but when i refresh the browser it works properly

+4  A: 

Sounds like a caching issue. Try adding some of the lines found here to your ashx file and it should hopefully force the browser to rerequest the image. (I know that the link is for ASP rather than ASP.NET, but things like Response.Expires = -1 should work)

Alternatively, can you change the path to the image in the updatepanel? If you just add a random parameter on to the end of it the browser will treat it as a fresh request (we use the current date/time as a parameter when we're doing this. The parameter is ignored by ASP.NET unless you explicitly reference it)

Matthew Steeples
I agree! You can solve this problem by adding response header.
Soul_Master
A: 

Do something like this:

var sPath = "../../handlers/ProcessSignature.ashx?type=View&UserID=" + userID + "&d=" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);

That puts a 4 character alpha numeric string at the end of your query string. It's not needed, but it will force browsers to pick up the latest version of that image because the URL is different.

I tried the above and some browsers ignore the headers. I threw all of those in and Chrome/FireFox 3 didn't try to update.

IE7 worked sometimes

IE6 just twiddled it's thumbs and asked why it was still in existence.

Changing the path above will fix it in all browsers.

Ryan Ternier