服务器错误:无法修改Controls集合,因为控件包含代码块(即<%...%>)

时间:2013-07-24 17:13:03

标签: c# asp.net code-behind web-controls

我添加的控件和控件本身都不包含<%=%><% %>块。我为什么要这个?这是我的图表页面的代码隐藏,其中包含有问题的行(标有注释),Charts.asx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Telerik.Web.UI;

namespace DashboardX.pages
{
    public partial class Charts : System.Web.UI.UserControl
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            // PROBLEM IS HERE!!!
            PlaceHolder1.Controls.Add(ColumnPanel);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        public void DownloadColumnChart(object sender, EventArgs e)
        {
            DownloadImage(sender, e, RadHtmlChart1, DropDownList1);
        }

        public void DownloadPieChart(object sender, EventArgs e)
        {
            DownloadImage(sender, e, RadHtmlChart2, DropDownList2);
        }

        public void DownloadBarChart(object sender, EventArgs e)
        {
            DownloadImage(sender, e, RadHtmlChart3, DropDownList3);
        }

        public void DownloadLineChart(object sender, EventArgs e)
        {
            DownloadImage(sender, e, RadHtmlChart4, DropDownList4);
        }

        /// <summary>
        /// Downloads an image of the given RadHtmlChart (with the given dropdown
        /// providing the format specification [PNG/PDF]) by launching Inkscape and
        /// passing some command line arguments.
        /// </summary>
        /// <param name="sender">Who ran this function?</param>
        /// <param name="e">Event data.</param>
        /// <param name="chart">The chart of which to generate an image.</param>
        /// <param name="ddl">The dropdown list with the format desired selected.</param>
        public void DownloadImage(object sender, EventArgs e, RadHtmlChart chart, DropDownList ddl)
        {
            //obtain the necessary settings for exporting the chart
            HtmlChartExportSettings currentSettings = new HtmlChartExportSettings();

            if (chart.Height != null && chart.Width != null)
            {
                currentSettings.Height = (int)chart.Height.Value;
                currentSettings.Width = (int)chart.Width.Value;
            }

            //decodes the SVG string saved from the client
            string svgText = HttpUtility.UrlDecode(svgHolder.Value);

            //create a temporary SVG file that Inkscape will use
            currentSettings.SvgFilePath = Server.MapPath("~/App_Data/temp.svg");
            System.IO.File.WriteAllText(currentSettings.SvgFilePath, svgText);

            //get the export format - png or pdf
            currentSettings.Extension = ddl.SelectedValue;

            //the output file Inkscape will use, hardcoded to use App_Data as a temporary folder
            currentSettings.OutputFilePath = (@"C:\chart." + currentSettings.Extension);

            //you can change the name of the file the user will receive here. Extension is automatically added
            currentSettings.ClientFileName = "chart";

            //the actual file is created
            HtmlChartExporter.ExportHtmlChart(currentSettings);

            //read the exported file and send it to the client
            byte[] fileForClient = HtmlChartExporter.ReadFile(currentSettings.OutputFilePath);
            Response.ContentType = HtmlChartExportSettings.ContentTypeList[currentSettings.Extension];
            Response.AddHeader("Content-Disposition", "attachment;filename=" + currentSettings.ClientFileName);
            Response.BinaryWrite(fileForClient);

            //delete the temporary files to avoid flooding the server
            File.Delete(currentSettings.OutputFilePath);
            File.Delete(currentSettings.SvgFilePath);

            svgHolder.Value = "";
        }
    }
}

以下是父母的代码:

<div id="graphs">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="PlaceHolder2" runat="server">
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="PlaceHolder3" runat="server">
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="PlaceHolder4" runat="server">
    </asp:PlaceHolder>
</div>

以下是孩子们:

<asp:Panel ID="ColumnPanel" runat="server" Height="405px" Width="450px" CssClass="left hidden">
    <div id="column" class="graph">
        <div class="download-image">
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Text="PNG" Value="png" Selected="true"></asp:ListItem>
                <asp:ListItem Text="PDF" Value="pdf"></asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button1" runat="server" Text="Download Image" OnClick="DownloadColumnChart" OnClientClick="getSvgContent(this, 'RadHtmlChart1'); return false;" />
        </div>
        <telerik:RadHtmlChart ID="RadHtmlChart1" runat="server" DataSourceID="SqlDataSource_TotalSales">
            <PlotArea>
                <Series>
                    <telerik:ColumnSeries DataFieldY="TotalSales">
                        <LabelsAppearance DataFormatString="{0:C}" Visible="false" />
                        <TooltipsAppearance DataFormatString="{0:C}" />
                    </telerik:ColumnSeries>
                </Series>
                <XAxis DataLabelsField="SubmitDate" MajorTickType="Outside" Step="1" MinorTickType="None">
                    <MinorGridLines Visible="false" />
                    <MajorGridLines Visible="false" />
                    <LabelsAppearance RotationAngle="-70" DataFormatString="{0}">
                    </LabelsAppearance>
                </XAxis>
                <YAxis>
                    <LabelsAppearance DataFormatString="${0}">
                    </LabelsAppearance>
                </YAxis>
            </PlotArea>
            <Legend>
                <Appearance Visible="false">
                </Appearance>
            </Legend>
        </telerik:RadHtmlChart>
    </div>
</asp:Panel>
<asp:Panel ID="PiePanel" runat="server" Height="405px" Width="450px" CssClass="hidden">
    <div id="pie" class="graph">
        <div class="download-image">
            <asp:DropDownList ID="DropDownList2" runat="server">
                <asp:ListItem Text="PNG" Value="png" Selected="true"></asp:ListItem>
                <asp:ListItem Text="PDF" Value="pdf"></asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button2" runat="server" Text="Download Image" OnClick="DownloadPieChart" OnClientClick="getSvgContent(this, 'RadHtmlChart2'); return false;" />
        </div>
        <telerik:RadHtmlChart ID="RadHtmlChart2" runat="server"
            Transitions="true" DataSourceID="SqlDataSource_TotalSales">
            <PlotArea>
                <Series>
                    <telerik:PieSeries DataFieldY="TotalSales" StartAngle="90">
                        <LabelsAppearance ClientTemplate="#=dataItem.SubmitDate#" Position="Circle" 
                        DataFormatString="{0:C}">
                        </LabelsAppearance>
                        <TooltipsAppearance DataFormatString="{0:C}" />
                    </telerik:PieSeries>
                </Series>
                <XAxis DataLabelsField="SubmitDate" Visible="true">
                </XAxis>
                <YAxis>
                    <LabelsAppearance DataFormatString="{0:C}">
                    </LabelsAppearance>
                </YAxis>
            </PlotArea>
            <Legend>
                <Appearance Visible="false">
                </Appearance>
            </Legend>
        </telerik:RadHtmlChart>
    </div>
</asp:Panel>
<asp:Panel ID="BarPanel" runat="server" Height="405px" Width="450px" CssClass="left hidden">
    <div id="bar" class="graph">
        <div class="download-image">
            <asp:DropDownList ID="DropDownList3" runat="server">
                <asp:ListItem Text="PNG" Value="png" Selected="true"></asp:ListItem>
                <asp:ListItem Text="PDF" Value="pdf"></asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button3" runat="server" Text="Download Image" OnClick="DownloadBarChart" OnClientClick="getSvgContent(this, 'RadHtmlChart3'); return false;" />
        </div>
        <telerik:RadHtmlChart ID="RadHtmlChart3" runat="server" DataSourceID="SqlDataSource_TotalSales">
            <PlotArea>
                <Series>
                    <telerik:BarSeries DataFieldY="TotalSales">
                        <LabelsAppearance DataFormatString="{0:C}" Visible="false" />
                        <TooltipsAppearance DataFormatString="{0:C}" />
                    </telerik:BarSeries>
                </Series>
                <XAxis DataLabelsField="SubmitDate" MajorTickType="None" MinorTickType="None">
                    <MinorGridLines Visible="false" />
                    <MajorGridLines Visible="false" />
                    <LabelsAppearance RotationAngle="0" DataFormatString="{0}">
                    </LabelsAppearance>
                </XAxis>
                <YAxis>
                    <LabelsAppearance DataFormatString="${0}">
                    </LabelsAppearance>
                </YAxis>
            </PlotArea>
            <Legend>
                <Appearance Visible="false">
                </Appearance>
            </Legend>
        </telerik:RadHtmlChart>
    </div>
</asp:Panel>
<asp:Panel ID="LinePanel" runat="server" Height="405px" Width="450px" CssClass="hidden">
    <div id="line" class="graph">
        <div class="download-image">
            <asp:DropDownList ID="DropDownList4" runat="server">
                <asp:ListItem Text="PNG" Value="png" Selected="true"></asp:ListItem>
                <asp:ListItem Text="PDF" Value="pdf"></asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button4" runat="server" Text="Download Image" OnClick="DownloadLineChart" OnClientClick="getSvgContent(this, 'RadHtmlChart4'); return false;" />
        </div>
        <telerik:RadHtmlChart ID="RadHtmlChart4" runat="server" DataSourceID="SqlDataSource_TotalSales">
            <PlotArea>
                <Series>
                    <telerik:LineSeries DataFieldY="TotalSales">
                        <LabelsAppearance DataFormatString="{0:C}" Visible="false" />
                        <TooltipsAppearance DataFormatString="{0:C}" />
                    </telerik:LineSeries>
                </Series>
                <XAxis DataLabelsField="SubmitDate" MajorTickType="Outside" MinorTickType="None">
                    <MinorGridLines Visible="false" />
                    <MajorGridLines Visible="false" />
                    <LabelsAppearance RotationAngle="-70" DataFormatString="{0}">
                    </LabelsAppearance>
                </XAxis>
                <YAxis>
                    <LabelsAppearance DataFormatString="${0}">
                    </LabelsAppearance>
                </YAxis>
            </PlotArea>
            <Legend>
                <Appearance Visible="false">
                </Appearance>
            </Legend>
        </telerik:RadHtmlChart>
    </div>
</asp:Panel>

0 个答案:

没有答案