Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Changing mouse pointer before and after excel export
posted

Hi,

I need to change the mouse pointer to hourglass before the excel export starts and change it back to default after it is done. I am changing the cursor to hourglass when I click on the image button that starts the export. However, I can't get back to the page I was on to change the mouse pointer back to default. Looks like the control is lost for that page. I tried to do it inside the EndExport event which I thought would be my last chance to change the mouse pointer back to normal, however the javascript I ran from the event method had no effect at all. So effectively when I come back to the page, the cursor is still hourglass. Is there a way to get control back to the page so that either the page can be refreshed or mouse pointer can be changed? The reason I need to do it because the databinding and actual export is taking much longer due to size of the data. Thanks a bunch.

 

Parents
  • 4960
    posted

    HTTP has a request-response message exchange pattern, meaning each HTTP request from the browser can have only one HTTP response from the server.

    So when you postback to do an Export, the HTTP response from the server is going to be the binary Excel (.XLS) file.  If in addition to the Export, you make any other changes that you expect to affect the HTML or Javascript on the page such as for example changing the mouse pointer style, during this same request, they won't have any effect (because the response was only an Excel file, no HTML).

    One approach I have seen used in situations where the client can't digest a binary XLS file or doing so throws things out of whack (you know, you're an AJAX UpdatePanel and you only speak JSON and then this binary Excel file hits you and you have no idea how to deal with it), is to trigger the export from within a hidden (or not so hidden) iframe.  That way the Excel file hits the iframe and not the rest of the page.  This is still good enough to convince the browser to do what it's supposed to do, prompt the user to open or save the Excel file.  It may allow you to kick-off a second HTTP request that updates the HTML or Javascript on the page and changes the cursor CSS style back to what you want.

    See what pgrimes629 did for an example of this approach (it's not a clean fit to your problem but it shows one way to set-up the iframe, and using a modal window may be an alternative):
    https://es.infragistics.com/community/forums/f/ultimate-ui-for-wpf/46798/auto-generate-fields-just-for-an-interface#46798.

    You'll still have a challenge figuring out when the Excel file has finished downloading, to deactivate the hourglass cursor, since the two HTTP requests will be asynchronous (and the one to get the updated mouse cursor will probably be much faster than the Excel export).  Hopefully my explanation can help you hone in on where the trouble lies.

Reply Children