【问题标题】:ReportViewer 15.0.0 Renerding: Sys.ArgumentNullException: Value cannot be null. Parameter name: elementReportViewer 15.0.0 渲染:Sys.ArgumentNullException:值不能为空。参数名称:元素
【发布时间】:2019-11-07 18:48:45
【问题描述】:

我在使用 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:值不能为空。参数名称: 元素

当我查找堆栈跟踪时:

看来这个问题的根源是从主“报告”页面调用的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)。我会发布报告和参数,但是它们包含敏感信息。如何调试 ReportViewer 库内部的问题以解决此类问题?

【问题讨论】:

    标签: javascript webforms reportviewer


    【解决方案1】:

    非常棘手,我在 MasterPage 中运行了一个 C# 方法,它禁用了某些类型的控件,因此用户无法“编辑”页面,看起来像这样:

    //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);
        }
    }
    

    原来这是在报表查看器中“禁用”某些呈现的控件,这反过来又破坏了前端的 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2014-05-17
      相关资源
      最近更新 更多