ASP.NET AJAX 问题
我已经更新了一些代码以使用 Ajax Control 工具包 0911 beta,由于某种原因,在后面的代码中动态添加可折叠面板扩展器的代码现在会导致客户端 jscript 中出现以下错误...
Microsoft JScript 运行时错误:Sys.ArgumentException :控件和行为的值不能为空。 参数名称:元素
在...
$create = Sys.Component.create = function Sys$Component$create(type, properties, events, references, element) {
/// <summary locid="M:J#Sys.Component.create" />
/// <param name="type" type="Type"></param>
/// <param name="properties" optional="true" mayBeNull="true"></param>
/// <param name="events" optional="true" mayBeNull="true"></param>
/// <param name="references" optional="true" mayBeNull="true"></param>
/// <param name="element" domElement="true" optional="true" mayBeNull="true"></param>
/// <returns type="Object"></returns>
var e = Function._validateParams(arguments, [
{name: "type", type: Type},
{name: "properties", mayBeNull: true, optional: true},
{name: "events", mayBeNull: true, optional: true},
{name: "references", mayBeNull: true, optional: true},
{name: "element", mayBeNull: true, domElement: true, optional: true}
]);
if (e) throw e;
if (type.inheritsFrom(Sys.UI.Behavior) || type.inheritsFrom(Sys.UI.Control)) {
if (!element) throw Error.argument('element', Sys.Res.createNoDom);
}
我承认这只是一个测试版,但我无法找到解决方法,甚至无法理解这个非常简单的代码不再起作用的原因。
代码
private Panel GetReportPanel(DataRow dr, ReportParameter[] Params)
{
Panel pnlReport = new Panel();
pnlReport.ID = Uri.EscapeDataString(dr["ReportName"].ToString()) + "_MainReportContainer";
//Report Title Section
var pnlReportTitle = new Panel();
pnlReportTitle.CssClass = "ReportSectionTitle";
var tblReportTitle = new Table();
var trowReportTitle = new TableRow();
var tcellReportTitle = new TableCell();
var imgReportTitleExpand = new Image();
imgReportTitleExpand.ID = Uri.EscapeDataString("img" + dr["ReportName"].ToString() + "DataExpand");
tcellReportTitle.Controls.Add(imgReportTitleExpand);
trowReportTitle.Controls.Add(tcellReportTitle);
tcellReportTitle = new TableCell();
var lblReportTitle = new Label();
lblReportTitle.ID = Uri.EscapeDataString("lnk" + dr["ReportName"].ToString());
lblReportTitle.Text = "Functional " + dr["ReportName"].ToString();
tcellReportTitle.Controls.Add(lblReportTitle);
trowReportTitle.Controls.Add(tcellReportTitle);
tblReportTitle.Controls.Add(trowReportTitle);
pnlReportTitle.Controls.Add(tblReportTitle);
pnlReport.Controls.Add(pnlReportTitle);
//Report Section
var pnlReportSection = new Panel();
pnlReportSection.ID = Uri.EscapeDataString("pnlReportSection" + dr["ReportName"].ToString());
pnlReportSection.CssClass = "ReportSection";
pnlReportSection.ScrollBars = ScrollBars.None;
var pnlInnerReportSection = new Panel();
pnlInnerReportSection.CssClass = "ReportSection";
var rptControl = new ReportViewer();
rptControl.ID = "rpt" + dr["ReportName"].ToString().Replace(' ', '_');
rptControl.ProcessingMode = ProcessingMode.Remote;
rptControl.Width = new Unit("100%");
rptControl.ShowDocumentMapButton = false;
rptControl.ShowParameterPrompts = false;
rptControl.Visible = true;
rptControl.Height = new Unit("500px");
rptControl.AsyncRendering = (bool)dr["ASyncRenderingEnabled"];
rptControl.ServerReport.ReportPath = dr["SSRSReportPath"].ToString();
rptControl.ServerReport.ReportServerUrl = new Uri("http://horoap336/reportserver");
rptControl.ServerReport.SetParameters(Params);
pnlInnerReportSection.Controls.Add(rptControl);
pnlReportSection.Controls.Add(pnlInnerReportSection);
pnlReport.Controls.Add(pnlReportSection);
//Collapsable Panel Extender
var Extender = new AjaxControlToolkit.CollapsiblePanelExtender();
Extender.TargetControlID = pnlReportSection.ID;
Extender.ID = Uri.EscapeDataString(dr["ReportName"].ToString()) + "_Extender";
Extender.CollapsedSize = 0;
Extender.Collapsed = true;
Extender.ExpandControlID = lblReportTitle.ID;
Extender.CollapseControlID = lblReportTitle.ID;
Extender.AutoCollapse = false;
Extender.AutoExpand = false;
Extender.ScrollContents = false;
Extender.TextLabelID = lblReportTitle.ID;
Extender.CollapsedText = "Functional " + dr["ReportName"].ToString() + " (Click To Show Details...)";
Extender.ExpandedText = "Functional " + dr["ReportName"].ToString() + " (Click To Hide Details...)";
Extender.ImageControlID = imgReportTitleExpand.ID;
Extender.ExpandedImage = "~/images/collapse.jpg";
Extender.CollapsedImage = "~/images/expand.jpg";
Extender.ExpandDirection = AjaxControlToolkit.CollapsiblePanelExpandDirection.Vertical;
pnlReport.Controls.Add(Extender);
return pnlReport;
}
然后使用... Aspx 文件将该面板添加到 aspx 文件中的面板
pnlContainer.Controls.Add(GetReportPanel(dr,Params));
...
<%@ Page Title="Operations MI Dashboard - Functional Reporting" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="FunctionalReport.aspx.cs" Inherits="TelephonyReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="pnlContainer" runat="server">
</asp:Panel>
</asp:Content>
所以,我的问题是:
- 我的代码是否存在问题 仅在后来的版本中明显 工具包的?
- 有谁知道 我可以尝试的解决方法吗?
- 谁能解释为什么这个问题 仅在最新版本中发生?
I've updated some code to use the Ajax Control toolkit 0911 beta and for some reason code that dynamically added collapsable panel extenders in the code behind now causes the following error in the client side jscript...
Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
Parameter name: element
in...
$create = Sys.Component.create = function Sys$Component$create(type, properties, events, references, element) {
/// <summary locid="M:J#Sys.Component.create" />
/// <param name="type" type="Type"></param>
/// <param name="properties" optional="true" mayBeNull="true"></param>
/// <param name="events" optional="true" mayBeNull="true"></param>
/// <param name="references" optional="true" mayBeNull="true"></param>
/// <param name="element" domElement="true" optional="true" mayBeNull="true"></param>
/// <returns type="Object"></returns>
var e = Function._validateParams(arguments, [
{name: "type", type: Type},
{name: "properties", mayBeNull: true, optional: true},
{name: "events", mayBeNull: true, optional: true},
{name: "references", mayBeNull: true, optional: true},
{name: "element", mayBeNull: true, domElement: true, optional: true}
]);
if (e) throw e;
if (type.inheritsFrom(Sys.UI.Behavior) || type.inheritsFrom(Sys.UI.Control)) {
if (!element) throw Error.argument('element', Sys.Res.createNoDom);
}
I accept that this is only a beta but I'm unable to either find a work around or even understand the reason why this pretty simple code no longer works.
Code
private Panel GetReportPanel(DataRow dr, ReportParameter[] Params)
{
Panel pnlReport = new Panel();
pnlReport.ID = Uri.EscapeDataString(dr["ReportName"].ToString()) + "_MainReportContainer";
//Report Title Section
var pnlReportTitle = new Panel();
pnlReportTitle.CssClass = "ReportSectionTitle";
var tblReportTitle = new Table();
var trowReportTitle = new TableRow();
var tcellReportTitle = new TableCell();
var imgReportTitleExpand = new Image();
imgReportTitleExpand.ID = Uri.EscapeDataString("img" + dr["ReportName"].ToString() + "DataExpand");
tcellReportTitle.Controls.Add(imgReportTitleExpand);
trowReportTitle.Controls.Add(tcellReportTitle);
tcellReportTitle = new TableCell();
var lblReportTitle = new Label();
lblReportTitle.ID = Uri.EscapeDataString("lnk" + dr["ReportName"].ToString());
lblReportTitle.Text = "Functional " + dr["ReportName"].ToString();
tcellReportTitle.Controls.Add(lblReportTitle);
trowReportTitle.Controls.Add(tcellReportTitle);
tblReportTitle.Controls.Add(trowReportTitle);
pnlReportTitle.Controls.Add(tblReportTitle);
pnlReport.Controls.Add(pnlReportTitle);
//Report Section
var pnlReportSection = new Panel();
pnlReportSection.ID = Uri.EscapeDataString("pnlReportSection" + dr["ReportName"].ToString());
pnlReportSection.CssClass = "ReportSection";
pnlReportSection.ScrollBars = ScrollBars.None;
var pnlInnerReportSection = new Panel();
pnlInnerReportSection.CssClass = "ReportSection";
var rptControl = new ReportViewer();
rptControl.ID = "rpt" + dr["ReportName"].ToString().Replace(' ', '_');
rptControl.ProcessingMode = ProcessingMode.Remote;
rptControl.Width = new Unit("100%");
rptControl.ShowDocumentMapButton = false;
rptControl.ShowParameterPrompts = false;
rptControl.Visible = true;
rptControl.Height = new Unit("500px");
rptControl.AsyncRendering = (bool)dr["ASyncRenderingEnabled"];
rptControl.ServerReport.ReportPath = dr["SSRSReportPath"].ToString();
rptControl.ServerReport.ReportServerUrl = new Uri("http://horoap336/reportserver");
rptControl.ServerReport.SetParameters(Params);
pnlInnerReportSection.Controls.Add(rptControl);
pnlReportSection.Controls.Add(pnlInnerReportSection);
pnlReport.Controls.Add(pnlReportSection);
//Collapsable Panel Extender
var Extender = new AjaxControlToolkit.CollapsiblePanelExtender();
Extender.TargetControlID = pnlReportSection.ID;
Extender.ID = Uri.EscapeDataString(dr["ReportName"].ToString()) + "_Extender";
Extender.CollapsedSize = 0;
Extender.Collapsed = true;
Extender.ExpandControlID = lblReportTitle.ID;
Extender.CollapseControlID = lblReportTitle.ID;
Extender.AutoCollapse = false;
Extender.AutoExpand = false;
Extender.ScrollContents = false;
Extender.TextLabelID = lblReportTitle.ID;
Extender.CollapsedText = "Functional " + dr["ReportName"].ToString() + " (Click To Show Details...)";
Extender.ExpandedText = "Functional " + dr["ReportName"].ToString() + " (Click To Hide Details...)";
Extender.ImageControlID = imgReportTitleExpand.ID;
Extender.ExpandedImage = "~/images/collapse.jpg";
Extender.CollapsedImage = "~/images/expand.jpg";
Extender.ExpandDirection = AjaxControlToolkit.CollapsiblePanelExpandDirection.Vertical;
pnlReport.Controls.Add(Extender);
return pnlReport;
}
This panel is then added to a panel in the aspx file using...
pnlContainer.Controls.Add(GetReportPanel(dr,Params));
Aspx file...
<%@ Page Title="Operations MI Dashboard - Functional Reporting" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="FunctionalReport.aspx.cs" Inherits="TelephonyReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="pnlContainer" runat="server">
</asp:Panel>
</asp:Content>
So, my questions are:
- Is there a problem with my code that
is only evident in the later version
of the toolkit? - Does anyone know of
a workaround that I can try? - Can anyone explain why this problem
happens only in the latest version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我最终通过反复试验解决了这个问题:)
由于某种原因,使用 Uri.EscapeDataString() 删除控件名称中的空格导致控件无法识别。
通过更改代码使用 string.Replace(' ','_') 现在可以工作了。然而,这确实意味着只有空格被转义,但这对于这个解决方案来说已经足够好了。
Ok, so I finally fixed this by trial and error :)
For some reason using Uri.EscapeDataString() to remove blank space in the control names was causing the controls to not be recognised.
By changing the code use string.Replace(' ','_') it now works. This does mean, however that only spaces are being escaped but thats good enough for this solution.