ReportViewer 15.0.0 渲染:Sys.ArgumentNullException:值不能为空。参数名称:元素
ReportViewer 15.0.0 Renerding: Sys.ArgumentNullException: Value cannot be null. Parameter name: element
我在使用 MS ReportViewer 呈现报告(具有特定参数集)时遇到以下问题。从内部 ReportViewer JS 代码调用的 JS 失败,具体是 "ScriptResource.axd":
这一段
var $addHandlers = Sys.UI.DomEvent.addHandlers = function Sys$UI$DomEvent$addHandlers(element, events, handlerOwner, autoRemove) {
/// <summary locid="M:J#Sys.UI.DomEvent.addHandlers" />
/// <param name="element"></param>
/// <param name="events" type="Object"></param>
/// <param name="handlerOwner" optional="true"></param>
/// <param name="autoRemove" type="Boolean" optional="true"></param>
var e = Function._validateParams(arguments, [
{name: "element"},
{name: "events", type: Object},
{name: "handlerOwner", optional: true},
{name: "autoRemove", type: Boolean, optional: true}
]);
if (e) throw e;
Sys.UI.DomEvent._ensureDomNode(element);
for (var name in events) {
var handler = events[name];
if (typeof(handler) !== 'function') throw Error.invalidOperation(Sys.Res.cantAddNonFunctionhandler);
if (handlerOwner) {
handler = Function.createDelegate(handlerOwner, handler);
}
$addHandler(element, name, handler, autoRemove || false);
}
}
"Sys.UI.DomEvent._ensureDomNode(element);" 行失败并出现以下错误:
Sys.ArgumentNullException: Value cannot be null. Parameter name:
element
当我查找堆栈跟踪时:
这个问题的根源似乎是从 "Report" 主页面调用的 JS:
Sys.Application.add_init(function() {
$create(Microsoft.Reporting.WebFormsClient._Splitter, {"HoverStyle":"SplitterHover","ImageCollapse":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapse.png","ImageCollapseHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapseHover.png","ImageExpand":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpand.png","ImageExpandHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpandHover.png","ImageId":"ctl00_ApplicationBody_rvReport_ToggleParam_img","IsCollapsable":true,"NormalStyle":"SplitterNormal","Resizable":false,"StoreCollapseField":"ctl00_ApplicationBody_rvReport_ToggleParam_collapse","StorePositionField":"ctl00_ApplicationBody_rvReport_ToggleParam_store","TooltipCollapse":"Hide Parameters","TooltipExpand":"Show Parameters","Vertical":false}, null, null, $get("ctl00_ApplicationBody_rvReport_ToggleParam"));
});
这会破坏呈现的报告。我不确定如何进一步追踪这个问题,我知道您可以使用不同的参数来格式化报告,但我不明白如何调试 ReportViewer 库内部的缩小 JS。
这个 JS 失败是否是某些报告的已知问题?我是运行最新版本的库(15.0.0)。我会 post 报告和参数,但它们包含敏感信息。 ReportViewer 库内部的调试问题如何解决此类问题?
非常棘手,我在 MasterPage 中有一个 C# 方法 运行 禁用某些类型的控件,因此用户无法 "Edit" 页面,看起来像这样:
//CommonFunctions
public static List<T> GetAllControlsRecursiveByType<T>(ControlCollection Controls) where T : Control
{
List<T> results = new List<T>();
foreach (Control c in Controls)
{
if (c is T)
{
results.Add((T)c);
}
if (c.HasControls())
{
results.AddRange(GetAllControlsRecursiveByType<T>(c.Controls));
}
}
return results;
}
public void DisableControls(Control control)
{
if (control == null)
{
return;
}
DisableControl(control);
foreach (System.Web.UI.Control c in control.Controls)
{
DisableControl(c);
// Recurse into child controls.
if (c.Controls.Count > 0)
{
DisableControls(c);
}
}
}
foreach (Control element in CommonFunctions.GetAllControlsRecursiveByType<Control>(FindControl("ApplicationBody").Controls))
{
List<string> excludedIDs = new List<string>() { "btnAjaxDynamicFilterApplyFilter", "btnClose", "btnCancel", "btnExport" };
List<Type> includedTypes = new List<Type>() { typeof(LinkButton), typeof(Button), typeof(ImageButton), typeof(Repeater), typeof(ABC.Controls.ABCRepeater),
typeof(GridView), typeof(ABC.Controls.ABCGridView), typeof(ABC.Controls.ImageCheckBox) };
if (!excludedIDs.Contains(element.ID) && includedTypes.Contains(element.GetType()))
{
DisableControls(element);
}
}
原来这是 "Disabling" 报表查看器中的某些渲染控件,这又破坏了前端的 JS。我通过从这个逻辑中排除 "ReportViewer" 来解决这个问题:
public bool ControlHasParentWithType(Control control, Type type)
{
if (control == null || control.Parent == null)
{
return false;
}
else if (control.Parent.GetType() == type)
{
return true;
}
return ControlHasParentWithType(control.Parent, type);
}
//Within Method before disabling the control
if (ControlHasParentWithType(element, typeof(ReportViewer)))
{
continue;
}
我在使用 MS ReportViewer 呈现报告(具有特定参数集)时遇到以下问题。从内部 ReportViewer JS 代码调用的 JS 失败,具体是 "ScriptResource.axd":
这一段var $addHandlers = Sys.UI.DomEvent.addHandlers = function Sys$UI$DomEvent$addHandlers(element, events, handlerOwner, autoRemove) {
/// <summary locid="M:J#Sys.UI.DomEvent.addHandlers" />
/// <param name="element"></param>
/// <param name="events" type="Object"></param>
/// <param name="handlerOwner" optional="true"></param>
/// <param name="autoRemove" type="Boolean" optional="true"></param>
var e = Function._validateParams(arguments, [
{name: "element"},
{name: "events", type: Object},
{name: "handlerOwner", optional: true},
{name: "autoRemove", type: Boolean, optional: true}
]);
if (e) throw e;
Sys.UI.DomEvent._ensureDomNode(element);
for (var name in events) {
var handler = events[name];
if (typeof(handler) !== 'function') throw Error.invalidOperation(Sys.Res.cantAddNonFunctionhandler);
if (handlerOwner) {
handler = Function.createDelegate(handlerOwner, handler);
}
$addHandler(element, name, handler, autoRemove || false);
}
}
"Sys.UI.DomEvent._ensureDomNode(element);" 行失败并出现以下错误:
Sys.ArgumentNullException: Value cannot be null. Parameter name: element
当我查找堆栈跟踪时:
这个问题的根源似乎是从 "Report" 主页面调用的 JS:
Sys.Application.add_init(function() {
$create(Microsoft.Reporting.WebFormsClient._Splitter, {"HoverStyle":"SplitterHover","ImageCollapse":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapse.png","ImageCollapseHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapseHover.png","ImageExpand":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpand.png","ImageExpandHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpandHover.png","ImageId":"ctl00_ApplicationBody_rvReport_ToggleParam_img","IsCollapsable":true,"NormalStyle":"SplitterNormal","Resizable":false,"StoreCollapseField":"ctl00_ApplicationBody_rvReport_ToggleParam_collapse","StorePositionField":"ctl00_ApplicationBody_rvReport_ToggleParam_store","TooltipCollapse":"Hide Parameters","TooltipExpand":"Show Parameters","Vertical":false}, null, null, $get("ctl00_ApplicationBody_rvReport_ToggleParam"));
});
这会破坏呈现的报告。我不确定如何进一步追踪这个问题,我知道您可以使用不同的参数来格式化报告,但我不明白如何调试 ReportViewer 库内部的缩小 JS。
这个 JS 失败是否是某些报告的已知问题?我是运行最新版本的库(15.0.0)。我会 post 报告和参数,但它们包含敏感信息。 ReportViewer 库内部的调试问题如何解决此类问题?
非常棘手,我在 MasterPage 中有一个 C# 方法 运行 禁用某些类型的控件,因此用户无法 "Edit" 页面,看起来像这样:
//CommonFunctions
public static List<T> GetAllControlsRecursiveByType<T>(ControlCollection Controls) where T : Control
{
List<T> results = new List<T>();
foreach (Control c in Controls)
{
if (c is T)
{
results.Add((T)c);
}
if (c.HasControls())
{
results.AddRange(GetAllControlsRecursiveByType<T>(c.Controls));
}
}
return results;
}
public void DisableControls(Control control)
{
if (control == null)
{
return;
}
DisableControl(control);
foreach (System.Web.UI.Control c in control.Controls)
{
DisableControl(c);
// Recurse into child controls.
if (c.Controls.Count > 0)
{
DisableControls(c);
}
}
}
foreach (Control element in CommonFunctions.GetAllControlsRecursiveByType<Control>(FindControl("ApplicationBody").Controls))
{
List<string> excludedIDs = new List<string>() { "btnAjaxDynamicFilterApplyFilter", "btnClose", "btnCancel", "btnExport" };
List<Type> includedTypes = new List<Type>() { typeof(LinkButton), typeof(Button), typeof(ImageButton), typeof(Repeater), typeof(ABC.Controls.ABCRepeater),
typeof(GridView), typeof(ABC.Controls.ABCGridView), typeof(ABC.Controls.ImageCheckBox) };
if (!excludedIDs.Contains(element.ID) && includedTypes.Contains(element.GetType()))
{
DisableControls(element);
}
}
原来这是 "Disabling" 报表查看器中的某些渲染控件,这又破坏了前端的 JS。我通过从这个逻辑中排除 "ReportViewer" 来解决这个问题:
public bool ControlHasParentWithType(Control control, Type type)
{
if (control == null || control.Parent == null)
{
return false;
}
else if (control.Parent.GetType() == type)
{
return true;
}
return ControlHasParentWithType(control.Parent, type);
}
//Within Method before disabling the control
if (ControlHasParentWithType(element, typeof(ReportViewer)))
{
continue;
}