当用户点击更新面板中的按钮时,我正在导出CSV。但是,为此,我使用下面的脚本来显示进度条
var updateProgress = null;
function postbackButtonClick()
{
updateProgress = $find("<%= UpdateProgress1.ClientID %>");
window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
return true;
}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function hideProgressBar()
{
$("#MainContent_UpdateProgress1").hide();
}
function EndRequestHandler(sender, args)
{
alert('End Request Handler');
if (args.get_error() != undefined)
{
var errorMessage = args.get_error().message;
alert(errorMessage);
}
}
function appl_init()
{
var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
pgRegMgr.add_beginRequest(postbackButtonClick);
pgRegMgr.add_endRequest(hideProgressBar);
}
我的HTML代码
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updatepanelDropDownTaskType"
class="Token-setup-popup">
<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">
<Triggers>
<asp:PostBackTrigger ControlID="btnExport" />
</Triggers>
<ContentTemplate>
<p style="text-align:right">
<asp:LinkButton ID="btnExport" runat="server" Text="Export To CSV" OnClick="btnExport_Click" OnClientClick="return postbackButtonClick()" ></asp:LinkButton>
</p>
</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();
由于上面的代码,我无法触发EndRequestHandler方法。任何解决此问题的建议