ReportViewer 15.0.0更新:Sys.ArgumentNullException:值不能为null。参数名称:元素

时间:2019-06-25 21:40:07

标签: javascript webforms reportviewer

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

当我查找堆栈跟踪时:

enter image description here

此问题的来源似乎是从“报告”主页面中调用的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库内部的问题来解决此类问题?

1 个答案:

答案 0 :(得分:0)

非常棘手,我在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;
}