进度条不会在response.end后隐藏
本文关键字:response end 隐藏 | 更新日期: 2023-09-27 18:17:46
我有功能下载excel文件在我的项目。单击导出按钮时,显示进度条。但即使浏览器的保存对话框出现,进度条也不是不可见的。问题是在回应之后。结束进度条未使用。进度条在asp.net ajax开始请求时可见,在请求结束时不可见。代码如下:
显示和隐藏进度条:
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
// alert('B');
var elem = args.get_postBackElement();
ActivateAlertDiv('visible', 'AlertDiv', elem.value + ' processing...');
}
function EndRequestHandler(sender, args) {
ActivateAlertDiv('hidden', 'AlertDiv', '');
}
function ActivateAlertDiv(visstring, elem, msg) {
var adiv = $get(elem);
adiv.style.visibility = visstring;
// adiv.innerHTML = msg;
}
和文件下载导出点击:
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + OUTPUTFILE + ".xls");
Response.AddHeader("Content-Type", "application/Excel");
Response.ContentType = "application/ms-excel.xls";
Response.AddHeader("Content-Length", file_New.Length.ToString());
Response.WriteFile(file_New.FullName);
Response.Flush();
file_New.Delete();
因为当文件发送到客户端时响应已经结束。你需要在新的页面做。
在中替换你的代码:
Session["OUTPUTFILE"] = OUTPUTFILE;
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'file.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=''+Mtop+'', left=''+Mleft+''' );", true);
新页面(名为"file.aspx"):
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + Session["OUTPUTFILE"].ToString()+ ".xls");
Response.AddHeader("Content-Type", "application/Excel");
Response.ContentType = "application/ms-excel.xls";
Response.AddHeader("Content-Length", file_New.Length.ToString());
Response.WriteFile(file_New.FullName);
Response.Flush();
file_New.Delete();
}