海滨小城

.net研究

导航

asp.net 代码实现打印功能

 asp.net 代码实现打印功能 收藏
一.在服务器端实现

 1.这个是在本页面上的.cs文件里写的
          if (resultInt > 0)
            {
                //清除验证码 ,显示执行结果,并转向新的地址
                Session["YanZhengMa"] = "";
                String caoCode = "if(confirm('提交成功,是否打印'))" +
              "{" +
                  "window.location.href='printTKZ.aspx?type=BF&BMId=" + _flowidValue +"&bufeitime="+ _jfTimeValue +"&palJE=" +_shouXianValue + "&goTo=buFeiList.aspx';" +
              "}" +
              "else" +
              "{" +
                  "window.location.href='buFeiList.aspx';" +
              "}";

                MessageBox.alert(Page, (object)caoCode);
            }

2.在你想要的打印 printTKZ.aspx这个页面上写上
  <body onload="vbscript:window.print()">
就可以了

二.在客户端实现

<script language="javascript">
  function doPrint() {
  bdhtml=window.document.body.innerHTML;
  sprnstr=" <!--startprint-->";
  eprnstr=" <!--endprint-->";
  prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
  prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
  window.document.body.innerHTML=prnhtml;
  window.print();
}
</script>
    <!--startprint-->  放在打印地方的开头
    <!--endprint-->打印地方的结尾
<a href="javascript:;" onclick="doPrint()">打  印 </a>


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chenjianyong94/archive/2009/05/08/4160596.aspx

posted on 2010-09-07 00:17  海滨小城  阅读(1255)  评论(1编辑  收藏  举报