asp.net – 更新面板PostBackTrigger,更新进度不显示

前端之家收集整理的这篇文章主要介绍了asp.net – 更新面板PostBackTrigger,更新进度不显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个更新面板,并使用PostBackTrigger事件更新进度.但是当我点击按钮时,没有显示更新进度.请找到以下示例代码
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updatepanelDropDownTaskType" CssClass="Token-setup-popup" DynamicLayout="true">
    <ProgressTemplate>
        <div id="loading" class="loading">
            <asp:Image runat="server" ID="imgBusyIndicator" ImageUrl="~/images/busy-indicator.gif" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="updatepanelDropDownTaskType" runat="server" UpdateMode="Conditional"> 
    <Triggers>
        <asp:PostBackTrigger ControlID="btnExport" />
    </Triggers>
    <ContentTemplate>     
            <asp:Button ID="btnExport" runat="server" Text="Export To CSV"  CssClass="button" CausesValidation="true" onclick="btnExport_Click" ClientIDMode="Static"/></asp:Button>
    </ContentTemplate>
</asp:UpdatePanel>

我的代码背后

HttpResponse Response = System.Web.HttpContext.Current.Response;
        Response.ClearHeaders();
        Response.AppendHeader("Content-Disposition","attachment; filename=" + FileName);
        Response.ContentType = FileType;
        Response.Write(content);
        HttpContext.Current.ApplicationInstance.CompleteRequest();

解决方法

那么你的代码还可以.问题在于您在UpdatePanel中使用的触发器.

微软说

The UpdateProgress control renders a <div> element that is
displayed or hidden depending on whether an associated UpdatePanel
control has caused an asynchronous postback. For initial page
rendering and for synchronous postbacks
,the UpdateProgress
control is not displayed.

查看有关MSDN的更多详细信息

因此,您在UpdatePanel中使用PostBackTrigger将导致同步回发,并且UpdateProgress将不会显示.

<Triggers>
    <asp:PostBackTrigger ControlID="btnExport" />
    // Incorrect
</Triggers>

将其更改为

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnExport" />
    // Correct
</Triggers>

这将显示您的UpdateProgress并将按预期工作.

正如您在评论中提到的那样,您也在网格上执行下载.您可以使用ScriptManager注册Button.这将注册您的按钮,并在异步回发时注意下载按钮.

protected void GridView_RowDataBound(object sender,GridViewRowEventArgs e)
 {    
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         Button btnExport = e.item.FindControl("btnExport") as Button;
         if (btnExport != null)
         {
             ((ScriptManager)this.Page.Master.FindControl("ID of your Script manager")).RegisterPostBackControl(downloadDocColumn);
             // In Above line i assumed Script Manager is placed on Your master page.
         }
     }
  }

希望这可以帮助…

原文链接:https://www.f2er.com/aspnet/248321.html

猜你在找的asp.Net相关文章