1

我在使用它生成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)
            {
            }
4

0 回答 0