在架構頁中彈出新視窗提供列印功能

來源:互聯網
上載者:User

1、首先利用一個類,ResponseHelper.cs,如下:

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Web;    using System.Web.UI;    public class ResponseHelper    {        public static void Redirect(string url, string target, string windowFeatures)        {            HttpContext context = HttpContext.Current;            if ((String.IsNullOrEmpty(target) || target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))            {                context.Response.Redirect(url);            }            else            {                Page page = (Page)context.Handler;                if (page == null)                {                    throw new InvalidOperationException("Cannot redirect to new window outside Page context.");                } url = page.ResolveClientUrl(url); string script; if (!String.IsNullOrEmpty(windowFeatures))                {                    script = @"<script>window.open(""{0}"", ""{1}"", ""{2}"");</script>";                }                else                {                    script = @"<script>window.open(""{0}"", ""{1}"");</script>";                }                script = String.Format(script, url, target, windowFeatures);                page.RegisterStartupScript("ddd", script);            }        }    }

2、在架構頁中,進行頁面跳轉,代碼:

ResponseHelper.Redirect("~/Vehicle/PrintTaskSheet.aspx?VID=" + braID, "_blank", "");

3、列印區代碼:

<style media="print">        .Noprint        {            display: none;        }        /*用本樣式在列印時隱藏非列印項目 */        .PageNext        {            page-break-after: always;        }        /*--控制分頁*/    </style>

 <!--引入一個object-->    <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"        width="0">    </object>
               <div align="center">                    <span class="Noprint">                        <input name="button2" type="button" class="formbotton" onclick="document.all.WebBrowser.ExecWB(6,6)"                            value="直接列印" />                        <input name="button2" type="button" class="formbotton" onclick="document.all.WebBrowser.ExecWB(8,1)"                            value="版面設定" />                        <input name="button2" type="button" class="formbotton" onclick="document.all.WebBrowser.ExecWB(7,1)"                            value="預覽列印" />                    </span>                </div>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.