我有一个更新面板,并使用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 associatedUpdatePanel
control has caused anasynchronous
postback. For initial page
rendering and forsynchronous
postbacks,theUpdateProgress
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. } } }
希望这可以帮助…