我有在我的项目中下载 excel 文件的功能。单击导出按钮时,显示进度条。但即使出现浏览器的另存为对话框,进度条也不会不可见。问题是在 response.end 进度条未使用之后。进度条在 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();