0

在 excel 文件下载期间,我试图拥有一个图像加载器。这是我当前的代码。

在 Javascript 中

function ShowProgress() {
    document.getElementById('<% Response.Write(prgLoadingStatus.ClientID); %>').style.display = "inline";
}

在 aspx 页面中

<asp:UpdatePanel ID="upAlignBuyer" runat="server" UpdateMode="Conditional" EnableViewState="true" >
<ContentTemplate>
    <asp:Button ID="Button2" Text="Download BWS" CssClass="app_button" 
        Font-Bold="true" value="DownloadExcel"  OnClick="Download_Click" OnClientClick="ShowProgress();"
        runat="server"  Height="23px" Width="120px"></asp:Button>
    <asp:UpdateProgress ID="prgLoadingStatus" runat="server" DynamicLayout="true" AssociatedUpdatePanelID="upAlignBuyer"  >
        <ProgressTemplate>
            <div id="overlay">
                <div id="modalprogress">
                    <div id="theprogress">
                        <asp:Image ID="imgWaitIcon" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/App_Themes/Images/progress.gif" />
                            Please wait...
                    </div>
                </div>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</ContentTemplate>
<Triggers>
    <asp:PostBackTrigger ControlID="Button2" />
</Triggers>
</asp:UpdatePanel>

所以这个问题是,加载图像正确加载并且文件被正确下载,但即使在文件下载后它仍然显示加载图像。任何帮助都会很棒。

4

1 回答 1

0

这可能不是一个好的解决方案,但我正朝着这个方向前进。看起来当文件被下载时,页面状态永远不会设置为“完成”,它总是以“交互式”结尾,所以这就是我修复它的方式。

document.onreadystatechange = function () {
      if (document.readyState === "interactive") {
                 HidePrograss();
      }
}

function ShowProgress() {
    document.getElementById('<% Response.Write(prgLoadingStatus.ClientID); 
             %>').style.display = "inline";
 }

function HidePrograss() {
      document.getElementById('<% Response.Write(prgLoadingStatus.ClientID); 
            %>').style.display = "none";
}

这样 updateprogress 将不会在任何时候显示,并且在文件下载期间它将设置为 display none 这是我想要的。

如果有人有更好的解决方案,请告诉我。

于 2017-11-09T23:17:17.980 回答