导出到excel时进度条问题

时间:2012-11-28 09:13:42

标签: c# asp.net progress-bar

我在使用它生成Excel报告时遇到了进度条的问题...

我想要实现的目标是: - 我尝试生成一个关于按钮的Excel报告,因为报告生成需要很长时间我想要一个进度条直到生成excel

问题: - 单击按钮时会显示进度条但在向用户提示excel下载后不会隐藏/禁用。进度条仍在那里......

我在更新面板中使用回发​​触发按钮来生成excel。并使用Response.Write()方法生成excel报告。

我正在使用pagerequestmanager来注册回发开始和结束处理程序。 请帮助我,我被困在这......

<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    //Raised before processing of an asynchronous postback starts and the postback request is sent to the server.
    prm.add_beginRequest(BeginRequestHandler);
    // Raised after an asynchronous postback is finished and control has been returned to the browser.
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        //Shows the modal popup - the update progress
        var popup = $find('<%= modalPopup.ClientID %>');
        if (popup != null) {
            popup.show();
        }
    }
    function EndRequestHandler(sender, args) {
        //Hide the modal popup - the update progress
        var popup = $find('<%= modalPopup.ClientID %>');
        if (popup != null) {
            popup.hide();
        }
    }
    function ShowProgress() {
        var myExtender = $find('<%= modalPopup.ClientID %>');

        myExtender.show();
        return true;
    }
</script>
<div>
<asp:UpdateProgress ID="updateProg" runat="server">
<ProgressTemplate>
<asp:Image ID="imgProg" ImageUrl="ajax-loader.gif" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<ajaxToolkit:ModalPopupExtender ID="modalPopup" runat="server" TargetControlID="updateProg" PopupControlID="updateProg" BackgroundCssClass="modalPopup" />
<asp:UpdatePanel ID="pnlData" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Excel" onclick="btnSubmit_Click" OnClientClick="return ShowProgress(); return false;"/>
</ContentTemplate>
<Triggers>
            <asp:PostBackTrigger ControlID="btnSubmit" />
        </Triggers>
</asp:UpdatePanel>
</div>

在按钮中单击我使用的是以下代码: -

try
            {
                Thread.Sleep(7000);
                Response.Clear();
                String Attachment = "attachment; filename=" + "MonitoringReport.xls";
                Response.ClearContent();
                Response.AddHeader("content-disposition", Attachment);
                Response.ContentType = "application/vnd.ms-excel";
                Response.Write("<table border=1 style='font-size:12px;'>");
                Response.Write("<th>" + "Col1" + "</th>");
                Response.Write("<th>" + "Col2" + "</th>");
                Response.Write("<th>" + "Col3" + "</th>");
                Response.Write("<th>" + "Col4" + "</th>");
                Response.Write("</table>");
                Response.End();
            }
            catch (ThreadAbortException ex)
            {
            }

0 个答案:

没有答案