title: Print the page and close it
body: <p>How can I print the page and close it automatically?</p>
  
  <p>I open a new window/page with button click:</p>
  
  <pre><code>protected void ASPxButton_GenerOrd_Click(object sender, EventArgs e)
  {
           string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&amp;SelId=" + TempId;
          ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("&lt;script&gt;window.open('{0}');&lt;/script&gt;", AdrUrl));
      }
  </code></pre>
  
  <p>my Print_Ordo.aspx :</p>
  
  <pre><code>&lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
       &lt;script&gt;         window.print(); window.close();&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;dx:ReportViewer ID="ReportViewer_Ordo" runat="server"&gt;
          &lt;/dx:ReportViewer&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and my Print_Ordo.aspx.cs:</p>
  
  <pre><code>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();
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>The problem is it does not close automaticaly. I tried with:</p>
  
  <pre><code>self.close();
  window.close();
  top.close();
  </code></pre>
  
  <p>None of this works. Any ideas?</p>
  
  <p>PS : as I look at it via Firebug:</p>
  
  <pre><code>&lt;embed width="100%" height="100%" name="plugin" src="http://172.18.1.253:4001/source/Print_Ordo.aspx?SoinId=4&amp;amp;SelId=9" type="application/pdf"&gt;
  </code></pre>
  
  <p>I think because of this process plugin, I can not close this window.</p>