Solved

Hiding Div after using response.binarywrite

Posted on 2013-12-19
5
1,430 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 39

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 39

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now