Page 1 of 1

Understanding Drawing and Download As Image

Posted: Fri May 26, 2023 12:54 pm
by 15695484
Hi,

I'm trying to understand why my chart is downloaded empty if I put the "drawing" code in a button event vs. putting it in the page load event. See attached example.

If the chart code is in the page-load event and I click the download button the chart with the data series is downloaded.
If the chart code is in the button-click event and I click the download button the chart without the data series is downloaded.

Thank you.

Re: Understanding Drawing and Download As Image

Posted: Wed May 31, 2023 2:18 pm
by Christopher
Key points to remember.
  • The Webform app is stateless and has no session memory although it is possible to ‘carry’ session memory by using “sessions” or via ViewState… (comments below).
  • Page_load is always called, but not the button code (only called when pressed) … so for every call first an empty page is loaded then page_load is called and then any button code is called
With those points in mind, every new call to the server has no knowledge of any previous call and starts from zero. In this case a call could be made to DrawChart from the button code that generates the PNG and it will return the chart but as the response is set as a png file, the chart itself isn’t rendered on the web page.

An extra point to note, when a button is actuated a page_load occurs followed by the button call method. The session is fluid between them and the chart thus shows six bars if both the page_load and the Buttonxx_Click contain a call to DrawChart.

-------

Possible solutions to carry state:

Use either:
Viewstate to carry data across calls.
See: https://www.c-sharpcorner.com/UploadFil ... Asp-Net53/

Or session; see example here:
https://github.com/Steema/TeeChart-NET- ... rt.aspx.cs

(here used to track a chart zoom to permit incremental zooms)
https://www.steema.net/TeeChartForNET/I ... Chart.aspx

Re: Understanding Drawing and Download As Image

Posted: Tue Jun 06, 2023 7:49 am
by 15695484
Thanks for the refresher.

Got it to work, thank you.