加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 04:27:03 所属栏目:asp.Net 来源:网络整理
导读:我有一个更新面板,并使用PostBackTrigger事件更新进度.但是当我点击按钮时,没有显示更新进度.请找到以下示例代码 asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updatepanelDropDownTaskType" CssClass="Token-setup-po
我有一个更新面板,并使用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.
         }
     }
  }

希望这可以帮助…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读