如何用aspx页面关闭窗口?

时间:2014-04-18 07:12:11

标签: c# asp.net

我在窗口中有一个aspx页面。现在我想从cs代码中关闭它:

 string result = @"<script type='text/javascript'>
                    window.returnValue = true;
                   window.close();
                 </script>";
 Response.Write(result);

工作正常 现在我要保存文件然后关闭一个窗口。而我上面的代码不起作用。我得到一个保存文件对话框,保存罚款,但我的窗口没有关闭 在这种情况下我该怎么做?

保存文件代码

                File.WriteAllBytes(docFileName, documentStream.ToArray());

            fi = new FileInfo(docFileName);
            if (fi.Exists)
            {
                byte[] buffer;
                using (FileStream fileStream = new FileStream(docFileName, FileMode.Open))
                {
                    int fileSize = (int)fileStream.Length;
                    buffer = new byte[fileSize];
                    // Read file into buffer
                    fileStream.Read(buffer, 0, fileSize);
                    fileStream.Close();


                    fi.Delete();

                }


                Response.Clear();
                Response.Buffer = true;
                Response.BufferOutput = true;
                Response.ContentType = "application/x-download";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + docFileName);
                Response.CacheControl = "public";
                // writes buffer to OutputStream
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.End();

1 个答案:

答案 0 :(得分:1)

你不能那样关闭窗口。

您只能关闭脚本创建的窗口。