2

我有一个<asp:button />生成 PDF 报告的文件。我想使用 jQuery BlockUI 来显示一条消息:生成报告..

使用:Response.BinaryWrite然后我将文件发送给用户,使其在浏览器中显示为文件下载。

我不能$.unblockUI();开火。一旦文件下载开始或完成或被取消,我希望它消失。目前它从来没有.. 就好像页面没有重新加载一样,我已经点击了服务器,但它返回了相同的页面。

我尝试过的事情:

  • 将JS中的变量 document.ready()设置为true,如果设置为true,它将调用一个函数。这不起作用,因为即使我更改了代码中的变量,它也不会更改发送到客户端的 HTML。
  • 这种事情:Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function() { $.unblockUI; }); //register with Microsoft way $(document).ajaxStop($.unblockUI); //double the insurance and register with jquery way 永远不会被调用..

这可以通过更新面板来实现吗?

有什么想法吗?

如果它有帮助:

Response.AddHeader("Content-Disposition", "attachment;filename=""" & ShortFilename & """")
        Response.AddHeader("Content-Length", byteArray.Length)
        Response.BinaryWrite(byteArray)
        Response.Flush()
        Response.End()

我可以明白为什么这不起作用,无论如何页面都没有刷新,只是有一个响应流被发送到浏览器,但肯定有一个事件我可以锁定?

4

2 回答 2

0

一个想法可能是创建一个执行 PDF 加载的子窗口,并让父级弄清楚子窗口何时关闭或其他什么。

父窗口是否可以注意到子窗口是否已关闭?

于 2011-09-26T10:25:00.787 回答
0

The solution is to first block the UI as normal. Then make an AJAX request to your report generator, when the PDF is generated store it locally for a short time, or have it in a temporary folder that is cleared out when the user logs out or their login times out. Have the report generator return a success message and a URL.

Have the client ajax request handle the success message, remove BlockUI, then call the URL using:

window.location="http://yourURL/temp/report.pdf

The browser will start to download the file and you are done!

https://stackoverflow.com/a/7660817/181197

于 2013-05-24T03:00:33.727 回答