|
Graph losing Images on page postback |
Posted by Mandar on Apr-27-2012 23:12 |
|
Hi Peter,
I have 2 CheckBoxList. Second CheckBoxList fills based on selection in the First One which has its AutoPostBack="true". Before all this i load a series of Graphs on my Page Load. So when i click on any value from the First CheckBoxList , second one fills up , however i lose all my graph images from my initial page load. Is there any way i can save my initial graph images?
I am using C#.net and my Graph loading funtion is placed in
if (!Page.IsPostBack)
{
DisplaysGraphs();
}
Thanks & Regards
Mandar |
Re: Graph losing Images on page postback |
Posted by Peter Kwan on Apr-28-2012 01:03 |
|
Hi Mandar,
In ASP.NET, when you create a web page, the state of the controls are sent to the browser for display. When you perform a "postback", the state of the controls are sent back from the browser to the server. So during postback, you usually do not need to re-initialize the controls. The browser have already sent the information back to the server. When the server updates the web page, it will send everything back to the browser again.
However, the above only works for controls with a small amount of data, such as list boxes, text boxes or other HTML controls. For charts, the data are much larger. The chart image itself can be dozens of KBytes to over 100 KBytes. If you use tooltips, the image map can be from 1 KBytes to a few hundred KBytes. Sending such large amount of data from the browser back to the server will be quite slow. So images are not included in the postback. When the server updates the web page, the suggested method is to recreate the charts, irrespective of whether it is a postback or not. This is usually much faster and more efficient than to postback the charts.
If you do not want to recreate the chart, one method is to store the chart and the image map on the server side. For example, when you create the charts, you can add the lines:
Session["mychart"] = myWebChartViewer.Image;
Session["myImageMap"] = myWebChartViewer.ImageMap;
Then during postback, you can use:
if (!Page.IsPostBack)
{
myWebChartViewer.Image = (ChartDirector.WebImage)Session["mychart"];
myWebChartViewer.ImageMap = (string)Session["myImageMap"];
}
Hope this can help.
Regards
Peter Kwan |
Re: Graph losing Images on page postback |
Posted by Mandar on Apr-30-2012 16:50 |
|
Hi Peter,
Saving my graph into session variable worked. Thanks again for you prompt support.
Regards,
Mandar |
|