Changing client side components' properties while server side execution happening in asp.net

388 Views Asked by At

I have a <asp:Button /> which is used to export some a DataTable into Excel. I need to display a progress image while the DataTable is being generated. Below is my try for this but still stuck. May be I haven't understand the life cycle here. Appreciate any help.
ASPX

<asp:Button ID="ExportResults" runat="server" UseSubmitBehavior="false" Text="Export Selected" OnClientClick="showWaitingForExport();" OnClick="ExportResults_Click"/>

JavaScript

function showWaitingForExport() {
  $("#progressbar").progressbar({ value: false });}

Code Behind

protected void ExportResults_Click(object sender, EventArgs e)
{
  DataTable resultDT = GenerateDataTable(); //This is the time taking function and after this I need to hide my progressbar while response still not get end

  ScriptManager.RegisterStartupScript(this, this.GetType(), "stopprogress", "$('#progressbar').progressbar('destroy');", true);

        string filename = "Search_Results.xlsx";
        workbook.AddWorksheet(resultDT, "Search Results");
        workbook.SaveAs(Server.MapPath("~/Temp/" + filename));
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
        Response.TransmitFile(Server.MapPath("~/Temp/" + filename));
        Response.End();
}
1

There are 1 best solutions below

3
On

Unless I misunderstood the question, check out this link - it's a fairly common thing that developers need to do: http://www.dotnetcurry.com/showarticle.aspx?ID=227

OnClientClick is called when you click the button, but then the request goes to the server (OnClick="ExportResults_Click") and the browser/client will show the normal loading page (usually a blank white page). You should be able to use an UpdatePanel with one of the strategies described in the link to show an update panel progress bar. The only way around this (that I'm aware of) is to use an async postback so the page is still displayed while the server is processing.

Does this make sense? Does the article help? I can go into more detail or show an example if necessary. I am not at a computer with Visual Studio to throw together an example, but I can post something tomorrow if no one else has answered.