• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1618
  • Last Modified:

Hiding Div after using response.binarywrite

I have one function which is downloading the excel file on browser. I need to show the progress bar to the end user till the time excel not downloaded and hide the same once downloaded. Issue is i am not able to hide the progress bar. Below is the code snippet i am using

<div id="progressbar" runat="server" align="center" style="display:none;position: fixed; z-index: 9; float: left; width: 848px; top: 224px; left: 32px;">
                <img alt="progress" src="images/loading.gif"/>                                      
            </div>

<asp:LinkButton ID="LinkButton1" OnClientClick="showprogressbar();" runat="server" onclick="LinkButton1_Click">Click here</asp:LinkButton>

function showprogressbar()
          {
              document.getElementById('<%= progressbar.ClientID%>').style.display = '';

            }

Server site code snippet

 public void Downloadlogfile()
    {
Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "filename=" + st + ".xls");
        Response.Clear();
        Response.BinaryWrite(WriteToStream().GetBuffer());
}

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Downloadlogfile();  
    }
0
vikalgupta
Asked:
vikalgupta
  • 2
  • 2
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Two ways I can think of:

1)
    Use a timer.  On the timer_tick event, hide the div.  Start the timer before response.binarywrite()

2)  Use a RegisterStartupScript to call a JS function that will hide the div for you.  (After the response.clear ).
0
 
vikalguptaAuthor Commented:
I tried 2 option but javascript is not firing.
 ClientScript.RegisterStartupScript(this.GetType(), "HideDiv", "$('#progressbar').style.display='none';", true);
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Try just an alert function to see if it's the javascript or if it's the register startup script.

I ended up using a timer in my app but forget why . . . you may need that second postback in order for it to work.
0
 
Kishan ZunjareCommented:
Hi

In .Net 4.5 version new keyword "async" and "await" provided for asynchronous programming.
You can use here.. for more info - http://msdn.microsoft.com/en-us/library/hh191443.aspx

Hope this helps.

- Kishan
0
 
vikalguptaAuthor Commented:
Good
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now