Solved

Hiding Div after using response.binarywrite

Posted on 2013-12-19
5
1,477 Views
Last Modified: 2014-01-08
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
Comment
Question by:vikalgupta
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39731187
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
 

Author Comment

by:vikalgupta
ID: 39731219
I tried 2 option but javascript is not firing.
 ClientScript.RegisterStartupScript(this.GetType(), "HideDiv", "$('#progressbar').style.display='none';", true);
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39732255
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
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 500 total points
ID: 39753559
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
 

Author Closing Comment

by:vikalgupta
ID: 39764746
Good
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question