簡體   English   中英

打印頁面並關閉它

[英]Print the page and close it

如何打印頁面並自動關閉?

我點擊按鈕打開一個新窗口/頁面:

protected void ASPxButton_GenerOrd_Click(object sender, EventArgs e)
{
         string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId;
        ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl));
    }

我的Print_Ordo.aspx:

<head runat="server">
    <title></title>
     <script>         window.print(); window.close();</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ReportViewer ID="ReportViewer_Ordo" runat="server">
        </dx:ReportViewer>
    </div>
    </form>
</body>
</html>

和我的Print_Ordo.aspx.cs:

public partial class Print_Ordo : System.Web.UI.Page
{

    string Soin_ID = "", SelectedID = ""; 
    protected void Page_Load(object sender, EventArgs e)
    {
        Soin_ID = Request.QueryString["SoinId"];
        SelectedID = Request.QueryString["SelId"];
        //ReportViewer_Ordo.Report = new XtraReport_Ordo(Convert.ToInt32(Soin_ID), SelectedID);
        //ReportViewer_Ordo.PageByPage = false;

        var xtraReport_Pricipal = new XtraReport_Ordo(Convert.ToInt32(Soin_ID), SelectedID);

        using (MemoryStream ms = new MemoryStream())
        {
            try
            {
                PdfExportOptions opts = new PdfExportOptions();
                opts.ShowPrintDialogOnOpen = true;
                xtraReport_Pricipal.ExportToPdf(ms, opts);
                ms.Seek(0, SeekOrigin.Begin);
                byte[] report = ms.ToArray();
                Page.Response.ContentType = "application/pdf";
                Page.Response.Clear();
                Page.Response.OutputStream.Write(report, 0, report.Length);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            finally
            {
                ms.Close();
            }
        }


    }
}

問題是它沒有自動關閉。 我嘗試過:

self.close();
window.close();
top.close();

這些都不起作用。 有任何想法嗎?

PS:我通過Firebug看一下:

<embed width="100%" height="100%" name="plugin" src="http://172.18.1.253:4001/source/Print_Ordo.aspx?SoinId=4&amp;SelId=9" type="application/pdf">

我想因為這個進程插件,我無法關閉這個窗口。

您可以嘗試使用此功能 - 在關閉之前在窗口上添加Focus

<script type="text/javascript">
    window.print();
    window.onfocus = function() { window.close(); }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM