An ASP.NET Chart control is refreshed on page post back -- but I don't want it to be.
In my aspx, I have:
<asp:Panel runat="server" ID="PanelRight" CssClass="roadmapRight">
<asp:Chart ID="ChartRemainingDaysHistory" runat="server">
<Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartAreaLineGraph">
<AxisY Title="Days Remaining" />
<AxisX Title="Date" IsLabelAutoFit="True">
<LabelStyle Angle="90" Interval="2" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</asp:Panel>
In the code behind:
protected void Page_Load(object sender, EventArgs e)
{
/* A bunch of code that needs to run */
if(IsPostback) return; // return if it is postback
// On first run build the graph
IQueryable<int> _users =
(metaPlanningDataContext.TasksCurrents.Where(....)).Distinct();
var s = new Series {
ChartType = SeriesChartType.Area,
Legend = "Engineer",
LegendText = "someName" };
foreach (DateTime dateTimeKey in someDataSet.Keys)
{
s.Points.AddXY(dateTimeKey.ToOADate(), someDataSet[dateTimeKey]);
}
}
The problem is that on a postback from some other control (Telerik RadGrid) the chart series contents disappear.
How can I secure the control from being destroyed in the postback?