1.前台一个javascript函数:     
<script type="text/javascript" language="javascript">
        function AAA() {
            debugger;
        }
</script>
2.后台通过 ClientScript.RegisterClientScriptBlock(Page.GetType(), "aaa", "<script">AAA();</script>");调用它,这样是可以的。
3.但是,如果我加了下面的导出功能时,却无效了。(有3行取消注释就前台JS函数没有执行)
        public static string openWindowExport(string strFileName)
        {
                FileInfo DownloadFile = new FileInfo(strFileName);
                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.ClearHeaders();
                System.Web.HttpContext.Current.Response.Buffer = false;
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                //System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="
                //    + System.Web.HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
                //System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
                System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);         
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
我要的目的:JS函数和导出都能执行。javascript无效导出导致后台不能执行前台

解决方案 »

  1.   

    因为此时页面上没有AAA(),你可以把js函数放在.js文件中,先输出到客户端:<script src="xxx.js" />
      

  2.   

    应该是页面js加载顺序导致的。试一试下面的写法可否
    ClientScript.RegisterClientScriptBlock(Page.GetType(), "aaa", "<script">window.onload=function(){AAA();}</script>")
      

  3.   

    不是顺序,是下面的代码存在的话就执行不了js,不知道为什么!
    你这种写法不好整。。把下载写到一个 iframe 中。
    当iframe 加载完毕时,就是文件下载完成时,那么再调用js 方法