views:

844

answers:

2

Using ASP.Net, JQuery and BlockUI, I'm trying to unblock the UI after a download file dialog is shown.

I block the UI when export button is clicked:

   <script type="text/javascript">     
    $(document).ready(function(){        
        $('#<%= BtnExport.ClientID%>').click(function(){
            $.blockUI(); 
        });
    });    
    </script>

After this, I generate the file server side using:

        private void SendFileToUser(byte[] file, string contentType, string filename)
        {
            Response.Clear();
            Response.ContentType = contentType;
            Response.AppendHeader("Content-Disposition", "attachment; filename="+filename);
            Response.OutputStream.Write(file,0,file.Length);
            Response.OutputStream.Flush();   
            Response.End();
        }

After this code has executed, I would like to unblock the UI.

I have considered different options:

  1. Poll using Ajax calls to see if the file has been generated.
  2. Store the file in Session and redirect to same page and generate download then.

But both options seem ackward, and I think there must be a clever JavaScript way to get a handle on or wait for a file dialog.

Any suggestions?

A: 

Don't store the file in the session, that's a huge waste of resources. Why not just post your form data to a "download" page with a "Your file should download momentarily..." message. This is how popular download sites like www.download.com do it when arrive at their download page.

This gives the user the opportunity to retry simply by refreshing, and you don't need to worry about session timeouts because all your data is in the POST header when they arrived at the page.

Soviut
A: 

Did you find any issue to this problem?

Jillustre