在ASP.Net Web窗体中的代码中关闭响应后,我调用了javascript函数的问题。
我的代码:
string CloseJS = "<script>window.parent.SaveToSAVAction.Close();</script>";
httpContext.Response.Clear();
httpContext.Response.ContentType = "application/force-download";
httpContext.Response.AppendHeader("Content-Disposition",header);
httpContext.Response.BinaryWrite(viewModel.Create());
httpContext.Response.Flush();
httpContext.Response.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), "closeScript", CloseJS);
也许有人知道如何修复它,或者知道下载字节数组的更好方法。
答案 0 :(得分:0)
您需要在关闭响应之前调用JavaScript。
创建.aspx
Generic Handler下载文件然后你可以这样称呼它
ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDiv()", true);
Response.Redirect("MyHandler.ashx")
OR
js函数隐藏div和Redirect
function HideDivNRedirect()
{
//hide div
window.location.href='myhandler.ashx';
}
ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDivNRedirect();", true);