1

I am implementing a export to excel functionality via ASP.net. i have a button control on a page. when i click the button, the control goes to the click event of the button. there i make a call to stored procedure to get the excel data. In Click event (codebeind) i have the below to code to download the data in excel file.

Response.Clear()
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.csv", "Report"))
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Response.Write("a,b,c") - sample output from SP.
Response.Flush();

All these works fine. the issue is - sometimes the procedure takes long time to execute, so in order to avoid the user messing up with UI untill the download starts, i have a javascript code to disable the UI when the download button is clicked. This is also working fine. but i am not able to call any javascript code to re-enable to UI, once the download has started or just before download starts. when i try to render a script before response.clear(in above code) and give response.flush, it gives me a error that i cannot change the response header once it is sent to client. how can i achieve this functionality?

Summary of question? i want to disable the UI from the time user has clicked on download button and till the actual download starts. once the download starts, i want to enable the UI back. How can i achieve this.

Thanks.

user1447718
  • 669
  • 1
  • 11
  • 23
  • Did you try document ready JQuery event to re-enable the UI ? http://api.jquery.com/ready/ – Guru Kara Apr 13 '13 at 02:54
  • I know abt document.ready, not sure how to use it in this context though... – user1447718 Apr 13 '13 at 05:28
  • In the document.ready just re-enable your UI (since its safe to assume on document reload the file upload is completed). Or take a look at this post it gives you feeling of AJAX file download. So there will be no need for you to even disable or re-enable controls. http://stackoverflow.com/questions/15953840/start-file-download-by-client-from-javascript-call-in-c-asp-net-page/15961851#15961851 – Guru Kara Apr 13 '13 at 05:31
  • My click event looks like this btn_click() { 1. make call to sp. Get the data. for , seperated string. 2. change the response header. 3. response.write the comma seperated string. This starts the download. } i want to trigger a javascript code after #1 and before #2. the problem is with above code, none of javascript is getting fired. even document.ready if i comment #2, javascript is getting fired. i cannot use iframes because, the sp returns 90,000X50 rows. so i cannot transfer the reader from one page to iframe. cannot use dataset as it throws memory exp. Appreciate the help, thanks. – user1447718 Apr 14 '13 at 02:54

0 Answers0