[英]Execute Javascript after postback with cleared response in C#
当用户单击我网站上的按钮时,我在服务器端制作了一个excel文件,并将其写入响应中。
HttpResponse httpResponse = Page.Response;
httpResponse.ClearHeaders();
httpResponse.ClearContent();
httpResponse.Clear();
httpResponse.Buffer = true;
httpResponse.AppendHeader("Content-Disposition",
"attachment; " +
"filename=\"" + fileName + "\";");
httpResponse.ContentType = "application/vnd.xlsx";
httpResponse.Charset = "";
using (MemoryStream memoryStream = new MemoryStream())
{
workbook.SaveAs(memoryStream);
memoryStream.WriteTo(httpResponse.OutputStream);
memoryStream.Close();
}
httpResponse.Flush();
httpResponse.End();
编写完该文件后,我希望运行一个JavaScript脚本块,但似乎无法完成这项工作。 我听说当我清除响应时,由于用户没有获得与响应相同的页面,所以无法使用Page.ClientScript.RegisterStartupScript
(不建议使用?)编写脚本块,但是我希望有一个解决方法。
进行回发和获取文件的按钮不在UpdatePanel中,因此我无法使用在那里实现的PageRequestManager.add_endRequest函数。 而且我无法将控件放入UpdatePanel中,因为它不允许我在异步回发中写入文件。
在回发结束时还有其他方法可以触发javascript函数吗? 检查间隔是否正在进行(或已完成)的JavaScript间隔函数也是一种可接受的解决方案(但据我所知,JavaScript无法“检查”同步间隔是否正在进行)。
Response.End()中止线程并将执行发送到Application_EndRequest。 在那之后什么也做不了。 您可以下载文件或执行javascript。 但是有使用iframe的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.