2009-06-10 56 views
2

我正在使用代码从弹出窗口导出pdf文件。ASP.NET中Crystal报表问题 - ExportToHttpResponse

在点击按钮

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中,弹出式窗口未关闭。为什么发生这种情况?

回答

0

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

试试这个workround关闭一个页面。

在您想要关闭的页面中编写一个脚本,该页面打开另一个页面;在这个示例中,脚本是在点击按钮后通过代码注入的,但如果需要,可以直接使用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>