views:

261

answers:

1

The following code works nicely:

<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);

    function InitializeRequest(sender, args) {
        document.body.style.cursor = 'progress';
    }
    function EndRequest(sender, args) {
        document.body.style.cursor = 'default';
    }
</script>

When the response returns an attachment, though (a PDF from the ReportViewer control, for instance):

Response.AddHeader("Content-Disposition", "attachment; filename=some.pdf")

EndRequest() never fires and the "progress" cursor is not reset. A Javascript call, e.g.

ScriptManager.RegisterStartupScript(this, this.GetType(), "close", 
   "parent.EndRequest(...);", true);

would do the trick, but is not possible because of the content disposition. Can you think of a way to do this correctly - show a wait cursor while a PDF is rendered, and return to the normal cursor when the PDF is displayed? I am assuming a C# context here, but the problem is not language- or platform-specific.

+1  A: 

The problem seems to be that the EndRequest function is not being fired. Have you tried to see if the pageLoading and the pageLoaded events are firing?

I have a feeling these events are not firing because there is nothing sent back to the page (the attachment doesn't reach the page the same way an inline document does).

I would move the file download into an iframe. Here is an example of how to do that:

function InitializeRequest(sender, args) {
    document.body.style.cursor = 'progress';

    var iframe = document.createElement("iframe");
    iframe.src = 'your pdf file';
    iframe.style.display = "none";
    document.body.appendChild(iframe); 
}

Then you can access the onload event of the iframe.

EDIT:

Further searching led me to this page. It seems to do all that you're looking to do.

Gabriel McAdams
pageLoaded is not fired either, and this makes sense in a way, because the response does not really make it back to the browser's page context. Nothing is loaded that replaces the current page.
cdonner
See modified answer. Includes more details.
Gabriel McAdams
The Iframe idea seems to work. Thanks a bunch.
cdonner
I'm glad we found a solution. Good luck with the rest of your project.
Gabriel McAdams