Forum Moderators: open

Message Too Old, No Replies

How do I refresh a image on a page

         

JohnBon

8:52 pm on May 20, 2003 (gmt 0)

10+ Year Member



Hi

I am drawing a graph based on values contained within a data base. Basically I create and save the graph as a gif

(call it graph.gif)

using a FileStream and then transfer contol to an different page using Server.Transfer("Differentpage.aspx",true).

Differentpage.aspx contains an image whose source is the file graph.gif

<asp:Image id="graph" runat="server" src="graph.gif" img="img" EnableViewState="False" ></asp:Image>

The graph displays properly the first time I access the page Differentpage.aspx but when I return to the referring page, change the query (and thus the graph)and I come back to the Differentpage.aspx , it always shows the original graph even though graph.gif has changed (I can see that graph.gif has indeed changed by viewing it in explorer).

Any ideas?

Thanks

John

sharbel

11:16 pm on May 20, 2003 (gmt 0)

10+ Year Member



You might consider rethinking your approach.

What you might want to do is create a page that displays your graph, and another page that draws the graph. What you do is change the output type to gif for the page that is creating the graph.. then on the page that is displaying it, the image controls src would be the .aspx page that creates the gif:

Page that displays the graph:

private void Page_Load(object sender, System.EventArgs e)
{
Image1.ImageUrl = "create_graph.aspx";
}

Page that generates the gif: (create_graph.aspx):

private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "image/gif";
//Create your graph here
// Save your image object to the output stream:
objBit.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);

}

If you need to pass some values to the second page, you can do it in the QueryString or Session and retrieve them in the Page_Load of the creat_graph.aspx page.

HTHs

jdMorgan

11:44 pm on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JohnBon,

Welcome to WebmasterWorld [webmasterworld.com]!

Assuming your original setup, you should mark the graph.gif file as "no-cache,must-revalidate." Otherwise, your browser will assume it already has a copy, and it will not re-request it from your server.

This will involve changing the default server headers for the file. I'm an Apache-type, so I'm not sure how you do that on IIS, but I'm sure that someone here knows. You could also do it in the script that generates the image if you use the approach described by sharbel.

HTH,
Jim

JohnBon

3:53 pm on May 21, 2003 (gmt 0)

10+ Year Member



Thanks!

I used Sharbels suggestion and output the graph directly to another page rather than create a file that was later referenced. Works great. Thanks again!

John