How to: Add a Chart to an ASPxCallbackPanel during its Callback (Runtime Sample)

  • 2 min to read

This tutorial demonstrates how a WebChartControl can be added to an ASPxCallbackPanel during its callback.

TIP

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E568.

  1. Create a new ASP.NET Web Application (Visual Studio 2008 or 2010), or open an existing one.
  2. Add the required assemblies to the project.

    Note that if you prefer that the assemblies be added automatically (by dropping a WebChartControl instance onto the page), this affects your web application's Web.config file. To learn about the changes being made to it, refer to Adding a Web Chart.

  3. Switch to the Design view of the Default.aspx page, and from the DX.19.2: Common Controls toolbox tab, drop an ASPxButton onto the page.

    HowTo_GenerateWebChart_0

  4. Then, click the button's smart tag. In the invoked actions list, disable the AutoPostBack property, and click Client-Side Events... link.

    In the invoked dialog, from within the client-side Click event handler, call the PerformCallback() for the callback panel.

    HowTo_ChartCallback

    To apply the changes, and quit the dialog, click OK.

  5. Now, from the DX.19.2: Navigation & Layout toolbox tab, drop an ASPxCallbackPanel onto the page.

    HowTo_ChartCallback_1

  6. Set its ClientInstanceName to panel, and handle its Callback event in the following way.

    
    using System;
    using DevExpress.XtraCharts;
    using DevExpress.XtraCharts.Web;
    using DevExpress.Web.ASPxClasses;
    using DevExpress.Web.ASPxCallbackPanel;
    // ...
    
    protected void ASPxCallbackPanel1_Callback(object sender, 
    CallbackEventArgsBase e) {
        WebChartControl wbc = new WebChartControl();
    
        wbc.Series.Add(new Series("Series", ViewType.Line));
        wbc.Series[0].ArgumentScaleType = ScaleType.DateTime;
        wbc.Series[0].ValueScaleType = ScaleType.Numerical;
    
        Random r = new Random();
        for (int i = 0; i < 5; i++) {
        wbc.Series[0].Points.Add(new SeriesPoint(DateTime.Today.AddDays(i),
            ((int)((r.NextDouble() * 100) * 10)) / 10.0));
        }
    
        wbc.Width = ((ASPxCallbackPanel)sender).Width;
        ((ASPxCallbackPanel)sender).Controls.Add(wbc);
    }
    

Run the application, and view the result.

HowTo_ChartCallback_2

See Also