views:

61

answers:

1

after the postback the chart control's values is changing its design time values. even when i write page load actions in (!isPostBack) scope , the values resets. so i defined a "my series" static ArrayList and in runtime i added each series of chart to that ArrayList. And in the page load event i added each element of ArrayList to Chart with Chart1.Series.Add(myseries[i] as Series) method. But it failed. "object reference not set to an instance of an object" error occured. Here is my code. Where am i wrong?

public partial class _Default : System.Web.UI.Page
{
   static ArrayList my_series = new ArrayList();

   void Fill_Chart();
   {
      ....
      foreach (Series item in Chart1.Series)
      {
          my_series.Add(item);
      }
   }

   protected void Page_Load(object sender, EvetnArgs e)
   {
      ...
      Chart1.Series.Clear();
      for (int i=0;i < my_series.Count;i++)
      {
         Chart1.Series.Add(my_series[i] as Series)
      }
   }

i checked this steps with debug. the error didnt occur after passing the line with F10. But when i passed last } symbol in page load event this error occurs.Any idea?

A: 

Why is my_series static? You can use like this:

public partial class _Default : System.Web.UI.Page
{
    private ArrayList mySeries;
    public ArrayList MySeries
    {
        get
        {
            if (mySeries == default(ArrayList))
                mySeries = new ArrayList();
            return mySeries;
        }
    }

   void Fill_Chart()
   {
      foreach (Series item in Chart1.Series)
      {
          MySeries.Add(item);
      }
   }

   protected void Page_Load(object sender, EvetnArgs e)
   {
      ...
      Chart1.Series.Clear();
      Fill_Chart();
      for (int i=0;i < MySeries.Count;i++)
      {
         Chart1.Series.Add(MySeries[i] as Series)
      }
   }
}
Musa Hafalır
i used static ArrayList. because i want to get hold chart values before postback. if it is not static, myseries will reset every postback. i did what you said. NullException error gone.But it is not useful for me. i dont want to use Fill_Chart method in PageLoad. Because the method does a lot of work with database spending a lot of time. i didnt want to run that method every postback. i want a way that my series wont reset after postback and NullException error has gone.
and with this code MySeries go on resetting itself every postback.i changed private mySeries to private static mySeries.NullException error came back.