报表查看器 Web 窗体导致页面挂起

ReportViewer Web Form causes page to hang

本文关键字:挂起 窗体 Web 报表      更新时间:2023-09-26

我被要求看看我们的一个小型仪表板 Web 应用程序的网页应该是什么简单问题。这个应用程序只显示我大量工作的底层后端应用程序的一些基本状态信息。问题如下:

在用户可以输入参数并请求查看具有给定用户输入的报表的页面上,按钮调用 JS 函数,该函数在浏览器中打开一个新页面以显示呈现的报表。代码如下所示:

$('#btnShowReport').click(function () {
    document.getElementById("Error").innerHTML = "";
    var exists = CheckSession();
    if (exists) {
        window.open('<%=Url.Content("~/Reports/Launch.aspx?Report=Short&Area=1") %>');
    }
});

然后打开的页面具有以下代码,该代码从Page_Load调用:

    rptViewer.ProcessingMode = ProcessingMode.Remote
    rptViewer.AsyncRendering = True
    rptViewer.ServerReport.Timeout = CInt(WebConfigurationManager.AppSettings("ReportTimeout")) * 60000
    rptViewer.ServerReport.ReportServerUrl = New Uri(My.Settings.ReportURL)
    rptViewer.ServerReport.ReportPath = "/" & My.Settings.ReportPath & "/" & Request("Report")
    'Set the report to use the credentials from web.config
    rptViewer.ServerReport.ReportServerCredentials = New SQLReportCredentials(My.Settings.ReportServerUser, My.Settings.ReportServerPassword, My.Settings.ReportServerDomain)
    Dim myCredentials As New Microsoft.Reporting.WebForms.DataSourceCredentials
    myCredentials.Name = My.Settings.ReportDataSource
    myCredentials.UserId = My.Settings.DatabaseUser
    myCredentials.Password = My.Settings.DatabasePassword
    rptViewer.ServerReport.SetDataSourceCredentials(New Microsoft.Reporting.WebForms.DataSourceCredentials(0) {myCredentials})
    rptViewer.ServerReport.SetParameters(parameters)
    rptViewer.ServerReport.Refresh()

我省略了一些为报告构建参数的代码,但我怀疑其中任何代码是否相关。

问题是,当用户单击显示报表按钮并打开此新页面时,根据他们使用的参数类型,报表可能需要相当长的时间才能呈现,同时,原始页面将完全无响应。报表页实际呈现的那一刻,主页将再次开始运行。如果我想修复此行为,以便其他页面可以异步加载而不影响主页,我应该从哪里开始(谷歌关键字、ReportViewer 属性等)?

编辑-

我尝试执行以下操作,这是此处评论中的链接答案:

            $.ajax({
                context: document.body,
                async: true,   //NOTE THIS
                success: function () { 
                    window.open(Address);
                }
            });

这替换了 Window.Open Call。这似乎有效,但是当我查看文档时,试图了解这是在做什么,我发现:

.context 属性在 jQuery 1.10 中已弃用,并且仅在 jQuery Migrate 插件中支持 .live() 所需的范围内进行维护。在未来的版本中,它可能会被删除,恕不另行通知。

我完全删除了上下文属性,它似乎根本不影响代码......是否可以以这种方式使用此 ajax 调用来打开另一个窗口,或者是否有更好的方法?

使用超时应该打开窗口而不会阻止您的主页

$('#btnShowReport').click(function () {
  document.getElementById("Error").innerHTML = "";
  var exists = CheckSession();
  if (exists) {
    setTimeout(function() {
      window.open('<%=Url.Content("~/Reports/Launch.aspx?Report=Short&Area=1") %>');
    }, 0);
  }
});

这是一个很长的镜头,但是您是否尝试先使用空白URL打开窗口,然后更改位置?

$("#btnShowReport").click(function(){
    If (CheckSession()) {
        var pop = window.open ('', 'showReport');
        pop = window.open ('<%=Url.Content("~/Reports/Launch.aspx?Report=Short&Area=1") %>', 'showReport');
    }
})

使用

`$('#btnShowReport').click(function () {
 document.getElementById("Error").innerHTML = "";
 var exists = CheckSession();
 if (exists) {
     window.location.href='<%=Url.Content("~/Reports/Launch.aspx?Report=Short&Area=1")       %>';
 }
 });`

它会起作用。