报表查看器打印对话框javascript呈现问题

时间:2015-10-26 12:27:52

标签: javascript asp.net reporting-services webforms

在我的网页表单页面上,我有一个报表查看器控件。我希望此控件仅显示打印对话框,因此我将报表查看器的显示CSS属性设置为none。 在加载报告后,将向用户显示打印对话框,以便他可以打印报告并关闭表单。 这个javascript代码如下:

        <script type="text/javascript">
        //Check if the query string contains parameters for printing or exporting
        $(document).ready(function () {
            var reportViewer = $find('<%=ReportViewer1.ClientID %>');

            //Add event handler to the reportviewer. When the loading is done, open the print dialog
            //See http://stackoverflow.com/questions/7194972/cant-find-reportviewer-event-for-rendering-complete
            Sys.Application.add_load(function () {
                reportViewer.add_propertyChanged(viewerPropertyChanged);
            });

            function viewerPropertyChanged(sender, e) {
                if (e.get_propertyName() == "isLoading") {
                    if (reportViewer.get_isLoading()) {
                        //Do something when loading starts
                    }
                    else {
                        //Do something when loading stops
                        var panelReportViewer = document.getElementById('<%=PanelReportViewer.ClientID%>');
                        if (panelReportViewer.style.display == "none") //if there are no server side errors this panel is not displayed
                        {
                            DoOutputAction(reportViewer);
                            window.close();
                        }
                        else {
                            divPleaseWait.style.display = "none";
                        }
                    }
                }
            }
        });
    </script>

DoOuputAction的内容:

function ClientPrint(reportViewerControl) {

    if (reportViewerControl != null) {
        //Check if a report is loaded and not an error message is shown
        var reportArea = reportViewerControl.get_reportAreaContentType();
        if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
            reportViewerControl.invokePrintDialog();
        }
    }
}

function ClientExport(reportViewerControl) {

    if (reportViewerControl != null) {
        //Check if a report is loaded and not an error message is shown
        var reportArea = reportViewerControl.get_reportAreaContentType();
        if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
            reportViewerControl.exportReport("PDF");
        }
    }
}

function DoOutputAction(reportViewerControl) {
    var param = $.getUrlVar('action');
    switch (param) {
        case 'print':
            ClientPrint(reportViewerControl);
            break;
        case 'PDF':
            ClientExport(reportViewerControl);
            break;
    }
}

我正在使用IE11,IIS 8.5在我自己的PC上开发它。这很好用。 当我将它发布到我的测试服务器,也就是IIS 8.5和IE11时,打印对话框没有显示! 在使用IE的开发者工具进行调查之后,我注意到用于在Reserved.ReportViewerWebControl.axd中显示打印对话框的渲染javascript是不同的! 我只显示不同的内容。

我的电脑:

PrintDialog: function()
{
    var printInfo = this.m_printInfo;
    if (printInfo == null)
        return false;

    var printObjectId = this.ReportViewerId + "_PrintObj";

    // Load the print control if it hasn't happened already
    var printObj = $get(printObjectId);
    if (printObj == null)
    {
        try
        {
            printObj = document.createElement("OBJECT");
            printObj.id = printObjectId;
            printObj.style.display = "none";
            printObj.ReportViewer = this;
            // Codebase must be before classid in order to download the control
            printObj.codeBase = printInfo.CabUrl;
            printObj.setAttribute("VIEWASTEXT", "");
            var reportViewer = $get(this.ReportViewerId);
            var printFunction = function() { this.ReportViewer.Print(false); };

            if (_$RVCommon.isIE10OrLower()) {
                printObj.onreadystatechange = printFunction;
                //Element must be added before printing occurs as the event can fire before this is added to the window.
                reportViewer.appendChild(printObj);
                printObj.classid = "CLSID:" + printInfo.CabClsid;
            } else {
                // printObj.onreadystatechange doesn't work on IE11 and beyond. The following is supported.
                printObj.addEventListener("readystatechange", printFunction);
                // Starting IE11, activex controls embedded in object elements aren't loaded if the classID isn't set before adding them to the tree.
                // If this behavior would be in previous versions as well, the onreadystatechange event wouldn't fire.
                // That's why the special behavior only for IE11.
                printObj.classid = "CLSID:" + printInfo.CabClsid;
                reportViewer.appendChild(printObj);
            }

            return true;
        }
        catch (exception)
        {
            alert(this.UnableToLoadPrintMessage);
            return false;
        }
    }
    else
    {
        return this.Print(true);
    }
},

从服务器呈现的打印对话框功能:

PrintDialog: function()
{
    var printInfo = this.m_printInfo;
    if (printInfo == null)
        return false;

    var printObjectId = this.ReportViewerId + "_PrintObj";

    // Load the print control if it hasn't happened already
    var printObj = $get(printObjectId);
    if (printObj == null)
    {
        printObj = document.createElement("OBJECT");
        printObj.id = printObjectId;
        printObj.onreadystatechange = this.OnPrintLoaded;
        printObj.style.display = "none";
        printObj.ReportViewer = this;
        // Codebase must be before classid in order to download the control
        printObj.codeBase = printInfo.CabUrl;
        printObj.setAttribute("VIEWASTEXT", "");

        //Element must be added before printing occurs as the event can fire before this is added to the window.
        var reportViewer = $get(this.ReportViewerId);
        reportViewer.appendChild(printObj);

        printObj.classid = "CLSID:" + printInfo.CabClsid;
        return true;
    }
    else
    {
        return this.Print();
    }
},

正如您所看到的,存在很多差异!

两台机器的web.config都是一样的。报告查看器版本是相同的。 AjaxControlToolKit dll是一样的。

有没有人遇到过同样的问题?

感谢您的帮助。

0 个答案:

没有答案