在框架页中弹出新窗口提供打印功能

简介: 1、首先利用一个类,ResponseHelper.cs,如下: using System; using System.

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>



相关文章
|
4月前
html+css+js完成代码弹出功能
html+css+js完成代码弹出功能
25 0
|
6月前
点击添加按钮弹框动态添加内容并且拼接在页面
点击添加按钮弹框动态添加内容并且拼接在页面
19 0
|
6月前
|
小程序 JavaScript 定位技术
小程序点击指定地址按钮直接打开地图导航
小程序点击指定地址按钮直接打开地图导航
131 0
|
6月前
|
小程序 开发者
小程序中点击按钮跳转另外一个小程序
小程序中点击按钮跳转另外一个小程序
240 0
|
10月前
|
存储
selenium+python:点击元素、alert弹框、鼠标操作(左键点击、右键点击、双击、鼠标悬浮)、下拉选项框、窗口切换等操作的处
selenium+python:点击元素、alert弹框、鼠标操作(左键点击、右键点击、双击、鼠标悬浮)、下拉选项框、窗口切换等操作的处
|
11月前
|
JSON 小程序 JavaScript
小程序地图插入图标后 怎么实现点击图标弹出窗口
小程序地图插入图标后 怎么实现点击图标弹出窗口
72 0
|
测试技术
clswindow使用案例:窗口图钉-窗口置顶(含源码)
clswindow使用案例:窗口图钉-窗口置顶(含源码)
197 0
clswindow使用案例:窗口图钉-窗口置顶(含源码)
|
JavaScript 前端开发
【Layui】关于做了分页后点击删除按钮无效(或者在任何框架点击一个按钮无效解决方案)
【Layui】关于做了分页后点击删除按钮无效(或者在任何框架点击一个按钮无效解决方案)
259 0
【Layui】关于做了分页后点击删除按钮无效(或者在任何框架点击一个按钮无效解决方案)