c# - ASP.NET 中的 Crystal Report 问题 - ExportToHttpResponse

标签 c# asp.net javascript crystal-reports export-to-pdf

我正在使用代码从弹出窗口导出 pdf 文件。

点击按钮

  function popupReport() 
    {
        var url = 'Report.aspx';
        window.open(url, 'winPopupReport', 'width=300,height=300,resizable=no,scrollbars=no,toolbar=no,directories=no,status=no,menubar=no,copyhistory=no');
        return false;
    }

并在 Report.aspx.cs 中

 ReportDocument repDoc = ( ReportDocument ) System.Web.HttpContext.Current.Session["StudyReportCrystalDocument"];
        // Stop buffering the response
        Response.Buffer = false;
        // Clear the response content and headers
        Response.ClearContent();
        Response.ClearHeaders();
        try
        {
            repDoc.ExportToHttpResponse( CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "StudyReport" );
        }
        catch( Exception ex )
        {
        }

该代码在 IE7 中运行良好。但是在 IE6 中,弹出窗口没有关闭。为什么会这样?

最佳答案

某些浏览器在某些情况下拒绝自动关闭网页。

尝试使用此解决方法关闭页面。

写一个脚本,在你想关闭的页面,打开另一个页面;在此示例中,脚本是在单击按钮后通过代码注入(inject)的,但如果需要,您可以直接用 HTML 编写它。

   ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('Success.htm', '_self', null);", true);

这样创建Success.htm页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head>
  <title></title>
  <script language="javascript" type="text/javascript">
   var redirectTimerId = 0;
   function closeWindow() {
      window.opener = top;
      redirectTimerId = window.setTimeout('redirect()', 2000);
      window.close();
  }

  function stopRedirect() {
     window.clearTimeout(redirectTimerId);
 }

  function redirect() {
     window.location = 'default.aspx';
 }
 </script>
</head>
<body onload="closeWindow()" onunload="stopRedirect()" style="">
   <center><h1>Please Wait...</h1></center>
</body></html>

关于c# - ASP.NET 中的 Crystal Report 问题 - ExportToHttpResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/973645/

相关文章:

c# - 有没有办法在一个单元测试中设置一个可以被另一个单元测试使用的值

.net - 以编程方式停止和启动 IIS。快速安全的方式

c# - 连接 DataTable 中两列的值

c# - SpreadsheetGear 在构造函数内抛出 IndexOutOfRangeException

javascript - 将 React 计时器重置为初始常量值

javascript - jQuery 事件监听器

javascript - 动态添加带有 src 的脚本标签,其中可能包含 document.write

javascript - ASP.NET MVC 包在本地工作但不在服务器中工作

c# - 在 UTF16 列中存储 UTF8 数据

c# - 来自 Windows 窗体应用程序的 ASP.NET 身份验证