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>