简体   繁体   中英

Creating new chart in c# throws Object reference not set to an instance of an object error

Below is part of the code I am using to create a new chart dynamically on a asp.net page. It throws the "Object reference not set to an instance of an object" error on chart1_holder.Controls.Add(chartCtrl); . Any reason why this is happening?

Chart chartCtrl;
chartCtrl = new Chart();

chart1_holder.Controls.Add(chartCtrl);

chartCtrl.DataBind();

ASP page

 <div id ="chart1_holder" runat="server" style="height:95%; width:100%"> </div>

Do you know at what point in the ASP.NET pipeline this code runs eg(Init,Load etc..)? It maybe that chart1_holder has not been initialised causing the null reference exception at the point you try to access any of its properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM