Unblock (jQuery BlockUI) after file sent to browser through response stream

↘锁芯ラ 提交于 2019-12-08 02:04:42

问题


I have an <asp:button /> that generates a PDF report. I want to use jQuery BlockUI to display a message that says: Generating Report..

Using: Response.BinaryWrite I am then sending the file to the user so it appears as a file download in the browser.

I cannot get $.unblockUI(); to fire. As soon as the file download begins or has completed or is cancelled I want it to dissappear. Currently it never does.. It's as though the page hasn't been re-loaded, I've hit the server but it comes back with the same page.

Things I have tried:

  • Setting a variable in JS to true so on document.ready() it will call a function if set to true. This doesn't work because even though I change the variable in code it doesn't change the HTML that is sent to the client.
  • This sort of thing: Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function() { $.unblockUI; }); //register with Microsoft way $(document).ajaxStop($.unblockUI); //double the insurance and register with jquery way never gets called..

Can this be achieved with an updatepanel?

Any thoughts?

Also in case it helps:

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

I can see why this doesn't work sort of, the page is not refreshing in anyway there's just a response stream being sent to the browser, but surely there's an event I can latch on to?


回答1:


An idea could be to create a child window that does the PDF loading and let the parent figure out when the child window has closed or something.

Is it possible for parent window to notice if child window has been closed?




回答2:


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



来源:https://stackoverflow.com/questions/3302131/unblock-jquery-blockui-after-file-sent-to-browser-through-response-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!