Question

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>
Was it helpful?

Solution

Do you know at what point in the ASP.NET pipeline this code runs e.g.(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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top