【问题标题】:How called javascript function after Response.Close()Response.Close() 之后如何调用 javascript 函数
【发布时间】:2015-02-17 08:01:18
【问题描述】:

在 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);

也许有人知道如何修复它,或者知道下载字节数组的更好方法。

【问题讨论】:

    标签: javascript c# asp.net .net webforms


    【解决方案1】:

    您需要在关闭响应之前调用 JavaScript。

    创建.aspx通用处理程序来下载文件然后你可以这样称呼它

    ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDiv()", true);
    Response.Redirect("MyHandler.ashx")
    

    隐藏div和重定向的js函数

    function HideDivNRedirect()
    {
      //hide div
    window.location.href='myhandler.ashx';
    }
    
    ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDivNRedirect();", true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 2021-05-08
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多