gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:46 25 4
gpt4 key购买 nike

我正在使用代码从弹出窗口导出 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com