p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Refresh imagebutton (http://p2p.wrox.com/showthread.php?t=47435)

ianH September 5th, 2006 11:28 PM

Refresh imagebutton
I have a problem with a web page that contains an imagebutton that displays a map generated by GDI commands and selected data from a gridview. The map is ‘live’ so that selecting a record in the gridview will highlight the point on the imagebutton, and vice versa. The map can also be zoomed and panned, so the image has to be constantly updated. The way I am doing this is to recreate the graphics, save the image as a bitmap file on the server and then reload it with ImageButton1.ImageUrl = "filename.bmp".

The problem is that while a new version of the image has been created and saved, it is not displayed – not unless I force a refresh. This generates the annoying msgbox “The page cannot be refreshed without resending the information…”. I presume this behaviour is due to caching, but other parts of the page are updated correctly without needing to refresh. For example a textbox can display the coordinates of the point clicked on the imagebutton. It seems to be only the image that is not updated.

So my questions are: 1. Is there a more direct way of updating the image on an imagebutton without having to save it to a file and then reload it? or 2. How can I force the latest version of the image to be retrieved from the server and displayed on the page? A solution of the first type would be preferable because that might also get around the problem of multiple visitors to the site generating multiple images.

I’m not sure if this is a “beginner” problem, but I am certainly a beginner when it comes to ASP.NET. Does anyone have any ideas?

ianH September 13th, 2006 04:40 PM

No response to this one yet but I have found a solution, so if anyone is interested:

The problem I had was an imagebutton whose image was created and updated by user actions. A jpg file was saved to the server and then loaded into the imagebutton by code. Unfortunately the new version of the image is not displayed without forcing a refresh. What I discovered was that the image for an imagebutton does not have to be a jpg, gif or other standard graphic file – it can be another aspx page (this is not immediately obvious from the standard resources). So now I draw the image onto an otherwise empty aspx page using objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg). In the main page this is accessed with ImageButton1.ImageUrl= "somepage.aspx?someparameters". And this way it works! I think the reason is that somewhere along the line, aspx files are assumed to be dynamic and so are not cached (unless you overrule this) but other files, like images, are assumed to be static and so are cached (possibly at several levels?) And there doesn’t seem to be a way to change this because there is no way to put directives like Response.CacheControl = "no-cache" into a jpg file. Am I correct?

I’m still not totally happy with this solution though because I have to pass a lot of data between aspx pages (or generate it twice) so if anyone knows of a more elegant (and efficient) way I would be grateful.

All times are GMT -4. The time now is 02:52 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.