Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

ASP.NET postback problem

Hi,

I am using the Carlos Web Chart Control on my aspx page, but everytime a postback occurs the Chart(rendered as an image) disappears.

//using this code the Chart disappears in postback
void Page_Load()
{
    if(!Page.IsPostBack)
    {
      CreateChart();
    }
}

//so I'm using this code which works but is unefficient...
void Page_Load()
{
      CreateChart();
}

//maybe this piece of code may also be helpfull in your solution
void CreateChart()
{
    LineChart chart = new  LineChart();
    chart.DataSource = GetDataSet().Tables[0].DefaultView;
    chart.DataXValueField = "Time";
    chart.DataYValueField = "Wavelenght";
    chart.LineMarker.Size = 0;
    chart.Line.Color=System.Drawing.Color.Blue;
    chart.Line.Width=2;
    chart.DataLabels.ForeColor = System.Drawing.Color.Blue;
    chart.DataBind();
    ChartControl1.Charts.Add(chart);
    ChartControl1.RedrawChart();
}



0
Raab314159
Asked:
Raab314159
1 Solution
 
David H.H.LeeCommented:
Raab314159,
If the created component is created dynamically, you need to re-create the chart for every postback unless you only deal with viewstate problems only. If the used component is static, you only need to make sure EnableViewState=True.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now