locked
Export AjaxToolkit Charts to Excel RRS feed

  • Question

  • User1344924657 posted

    I have several ajaxToolkit charts that I want to export to excel. I get the following error when I try to export. Script control 'PieChart1' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors(). Parameter name: scriptControl

    Here is my code:

    <%@ Page Title="Transfers w/ Data" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="TransfersWData.aspx.cs" Inherits="TransfersWData" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
        
        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <div class="modaldiv">
                    <div class="centerdiv">
                        <img alt="" src="images/loading_spinner.gif" />
                    </div>
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel runat="server" id="UpdatePanel1">
            <ContentTemplate>
        <div>
                    <table>
                        <tr>
                            <td>
                            <span class="h1">Period:</span><br />
                            <asp:DropDownList ID="ddlperiod" runat="server" AutoPostBack="True"
                                onselectedindexchanged="ddlperiod_SelectedIndexChanged">
                                <asp:ListItem Text="Last 30 Days" Value="30"></asp:ListItem>
                                 <asp:ListItem Text="Last 7 Days" Value="7"></asp:ListItem>
                                 <asp:ListItem Text="Last Week" Value="3" Selected="True"></asp:ListItem>
                                 <asp:ListItem Text="Last Month" Value="5"></asp:ListItem>
                                 <asp:ListItem Text="This Week" Value="2"></asp:ListItem>                            
                                 <asp:ListItem Text="This Month" Value="4"></asp:ListItem>
                                 <asp:ListItem Text="Yesterday" Value="1" ></asp:ListItem>
                                <asp:ListItem Text="Last 90 Days" Value="6"></asp:ListItem>
                            </asp:DropDownList>
                        </tr>
                        <div id="divLOB" runat="server">
                            <tr>
                                <td>
                                    <span style="font-weight:bold">LOB</span><br />
                                    <asp:DropDownList ID="ddlLOB" runat="server" CssClass="font">
                                        <asp:ListItem Text="All" Value="0" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Care" Value="Y"></asp:ListItem>
                                        <asp:ListItem Text="Collections" Value="C"></asp:ListItem>
                                        <asp:ListItem Text="PPD" Value="P"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Button ID="btnrun" runat="server" Text="Run" onclick="btnrun_Click" />
                                </td>
                                <td>
                                    <asp:Button ID="btnExportExcel" runat="server" Text="export"
                                        onclick="btnExportExcel_Click" />
                                </td>
                            </tr>
                        </div>
                    </table>
                    <asp:Panel ID="Panel1" runat="server">                    
                    <table>
                        <tr>
                            <td>
                                <ajaxToolkit:PieChart ID="PieChart1" runat="server" ChartHeight="250" ChartWidth ="350"
                                    ChartType="Column" ChartTitleColor="#0E426C" BorderStyle="None" Visible="False"
                                    ChartTitle="% Transfers with Data" Theme="">
                                </ajaxToolkit:PieChart>
                            </td>
                            <td>
                                <ajaxToolkit:PieChart ID="PieChartEnterpriseTransferSummary" runat="server"
                                    ChartHeight="250" ChartWidth ="350" Visible="False"
                                    ChartType="Column" ChartTitleColor="#0E426C" BorderStyle="None"
                                    ChartTitle="Enterprise Transfer Summary" Theme="">
                                </ajaxToolkit:PieChart>
                            </td>
                            <td>
                                <ajaxToolkit:PieChart ID="PieChartEnterpriseSoftphoneCompliance" runat="server"
                                    ChartHeight="250" ChartWidth ="350" Visible="False"
                                    ChartType="Column" ChartTitleColor="#0E426C" BorderStyle="None"
                                    ChartTitle="Enterprise Softphone Compliance" Theme="">
                                </ajaxToolkit:PieChart>
                            </td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td>
                                <ajaxToolkit:LineChart ID="LCEnterpriseTransferswithData" runat="server"
                                    BaseLineColor="black" CategoryAxisLineColor="black" ChartHeight="250"
                                    ChartTitleColor="#0E426C" ChartWidth="250"
                                    ValueAxisLineColor="black" Visible="False"
                                    ChartTitle="Enterprise Transfers with Data" Theme="" TooltipBackgroundColor=""
                                    TooltipBorderColor="" TooltipFontColor="" ValueAxisLines="0"
                                    AreaDataLabel="" CategoriesAxis="">
                                </ajaxToolkit:LineChart>
                            </td>
                            <td>
                                <ajaxToolkit:LineChart ID="LCPCTTransfersWData" runat="server"
                                    BaseLineColor="black" CategoryAxisLineColor="black" ChartHeight="250"
                                    ChartTitleColor="#0E426C" ChartWidth="250" ChartType="Stacked"
                                    ValueAxisLineColor="black" Visible="False"
                                    ChartTitle="% Transfers with Data" Theme="" TooltipBackgroundColor=""
                                    TooltipBorderColor="" TooltipFontColor="" ValueAxisLines="0"
                                    AreaDataLabel="" CategoriesAxis="">
                                </ajaxToolkit:LineChart>
                            </td>
                        </tr>
                    </table>
                    </asp:Panel>
                    
                </ContentTemplate>  
                </ajaxToolkit:TabPanel>    
               
            </ajaxToolkit:TabContainer>    
            </ContentTemplate>
        </asp:UpdatePanel>
        </asp:Content>

    void exportpanel()
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment; filename=FileName1.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

           

            Panel1.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
        }

    Monday, October 10, 2016 2:18 PM

All replies

  • User1283705980 posted

    Hi,

    I think you couldn't use RenderControl method to get the chart and export to excel.

    As far as I know, the AjaxToolkit Charts will generate a SVG file in html.

    I suggest you could refer to follow link to know how to convert SVG into excel。

    https://forums.asp.net/p/2069184/5970617.aspx

    Tuesday, October 11, 2016 12:34 PM