0

我有一个<asp:Button />用于将一些 a 导出DataTable到 Excel 中。我需要在DataTable生成时显示进度图像。下面是我的尝试,但仍然卡住了。可能是我不了解这里的生命周期。感谢任何帮助。
ASPX

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

JavaScript

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

代码背后

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();
}
4

1 回答 1

0

除非我误解了这个问题,否则请查看此链接 - 这是开发人员需要做的一件相当常见的事情: http: //www.dotnetcurry.com/showarticle.aspx?ID=227

单击按钮时会调用 OnClientClick,但随后请求会转到服务器(OnClick="ExportResults_Click"),并且浏览器/客户端将显示正常的加载页面(通常是空白页面)。您应该能够使用带有链接中描述的策略之一的 UpdatePanel 来显示更新面板进度条。解决这个问题的唯一方法(我知道)是使用异步回发,以便在服务器处理时仍然显示页面。

这有意义吗?文章有帮助吗?如有必要,我可以更详细地介绍或展示示例。我不是在使用 Visual Studio 的计算机上拼凑一个例子,但如果没有其他人回答,我明天可以发布一些东西。

于 2014-01-22T04:20:43.347 回答