<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/csharp-asp-net-webform-print-need-noneed/</link>
<title><![CDATA[c#实现web页面打印,可以控制需要打印和不需要打印的位置]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[Web开发]]></category>
<pubDate>Fri, 10 Sep 2010 07:36:46 +0000</pubDate> 
<guid>https://www.heckjj.com/csharp-asp-net-webform-print-need-noneed/</guid> 
<description>
<![CDATA[ 
	html页面的web打印示例 <br/><textarea name="code" class="html" rows="15" cols="100">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;无标题页&lt;/title&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;script id=Script1 language=javascript&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--
&nbsp;&nbsp;&nbsp;&nbsp;function preview()
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdhtml=window.document.body.innerHTML;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprnstr=&quot;&lt;!--startprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eprnstr=&quot;&lt;!--endprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(prnhtml);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.document.body.innerHTML=prnhtml;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.print();
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;--&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/script&gt;
&lt;/head&gt;
&lt;body&nbsp;&nbsp; &gt;
&lt;form id=&quot;WebForm1&quot; method=&quot;post&quot; runat=&quot;server&quot;&gt;
heck不被打印位置 一
&lt;center&gt;本部分以上不被打印&lt;/center&gt;
&lt;!--startprint--&gt;
&lt;div align=&quot;center&quot;&gt;
heck要打印位置 二
&lt;/div&gt;
&lt;!--endprint--&gt;
&lt;center&gt;本部分以下不被打印&lt;/center&gt;
heck不被打印位置 三
&lt;div align=&quot;center&quot;&gt;
&lt;input type=&quot;button&quot; name=&quot;print&quot; value=&quot;预览并打印&quot; onclick=&quot;preview()&quot;&gt;
&lt;/div&gt;
&lt;style&gt; @media Print &#123; .Noprn &#123; DISPLAY: none &#125;&#125;
&lt;/style&gt;
&lt;p class=&quot;Noprn&quot;&gt;不打印&lt;/p&gt;
&lt;table id=&quot;datagrid&quot;&gt;
&lt;tr&gt;
&lt;td&gt;普通打印&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input class=&quot;Noprn&quot; type=&quot;button&quot; onclick=&quot;window.print()&quot; value=&quot;print&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</textarea><br/>不带母版的aspx页面打印 <br/><textarea name="code" class="html" rows="15" cols="100">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;&nbsp;&nbsp;CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;script id=Script1 language=javascript&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--
&nbsp;&nbsp;&nbsp;&nbsp;function preview()
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdhtml=window.document.body.innerHTML;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprnstr=&quot;&lt;!--startprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eprnstr=&quot;&lt;!--endprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(prnhtml);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.document.body.innerHTML=prnhtml;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.print();
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;--&gt;
&lt;/script&gt;
&lt;head runat=&quot;server&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;无标题页&lt;/title&gt;
&lt;/head&gt;
&lt;body&nbsp;&nbsp; &gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
heck不被打印位置 一
&lt;center&gt;本部分以上不被打印&lt;/center&gt;
&lt;!--startprint--&gt;
heck发要打印位置 二
&lt;!--endprint--&gt;
&lt;center&gt;本部分以下不被打印&lt;/center&gt;
heck不被打印位置 三
&lt;div align=&quot;center&quot;&gt;
&lt;input type=&quot;button&quot; name=&quot;print&quot; value=&quot;预览并打印&quot; onclick=&quot;preview()&quot;&gt;
&lt;/div&gt;
&lt;style&gt; @media Print &#123; .Noprn &#123; DISPLAY: none &#125;&#125;
&lt;/style&gt;
&lt;p class=&quot;Noprn&quot;&gt;不打印&lt;/p&gt;
&lt;table id=&quot;datagrid&quot;&gt;
&lt;tr&gt;
&lt;td&gt;打印&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input class=&quot;Noprn&quot; type=&quot;button&quot; onclick=&quot;window.print()&quot; value=&quot;print&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;button&quot; name=&quot;print&quot; value=&quot;预览并打印&quot; onclick=&quot;preview()&quot;&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea><br/>带母版的aspx页面打印 <br/>要把js代码写在js文件里再调用,否则显示不正常 <br/>preview.js<br/><textarea name="code" class="html" rows="15" cols="100">// JScript 文件
&nbsp;&nbsp; &lt;!--
&nbsp;&nbsp;&nbsp;&nbsp;function preview()
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdhtml=window.document.body.innerHTML;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprnstr=&quot;&lt;!--startprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eprnstr=&quot;&lt;!--endprint--&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;prnhtml:&quot;+prnhtml);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.document.body.innerHTML=prnhtml;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.print();
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;--&gt;
</textarea><br/>aspx文件 <br/><textarea name="code" class="html" rows="15" cols="100">&lt;%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/public/MenuIndexContainerHeader.master&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;CFJDS.aspx.cs&quot; Inherits=&quot;private_dzjc_DYSZ_CFJDS&quot; Title=&quot;Untitled Page&quot; %&gt; 
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;ContentPlaceHolder1&quot; Runat=&quot;Server&quot;&gt; 
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot; src=&quot;../../js/Move.js&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot; src=&quot;../../js/preview.js&quot;&gt;&lt;/script&gt; 
heck不被打印位置 一 
&lt;!--startprint--&gt; 
heck要打印位置 二 
&lt;!--endprint--&gt; 
heck不被打印位置 三 
&lt;input type=&quot;button&quot; name=&quot;print&quot; value=&quot;预览并打印&quot; onclick=&quot;preview()&quot;&gt; 
&lt;/asp:Content&gt; </textarea><br/>html示例：<br/><a href="attachment.php?fid=45">点击这里下载文件</a><br/>aspx示例：<br/><a href="attachment.php?fid=46">点击这里下载文件</a><br/>Tags - <a href="https://www.heckjj.com/tags/c%2523/" rel="tag">c#</a> , <a href="https://www.heckjj.com/tags/asp.net/" rel="tag">asp.net</a> , <a href="https://www.heckjj.com/tags/webform/" rel="tag">webform</a> , <a href="https://www.heckjj.com/tags/web/" rel="tag">web</a> , <a href="https://www.heckjj.com/tags/%25E9%25A1%25B5%25E9%259D%25A2/" rel="tag">页面</a> , <a href="https://www.heckjj.com/tags/%25E6%2589%2593%25E5%258D%25B0/" rel="tag">打印</a> , <a href="https://www.heckjj.com/tags/%25E6%258E%25A7%25E5%2588%25B6/" rel="tag">控制</a> , <a href="https://www.heckjj.com/tags/%25E4%25B8%258D%25E9%259C%2580%25E8%25A6%2581/" rel="tag">不需要</a> , <a href="https://www.heckjj.com/tags/%25E4%25BD%258D%25E7%25BD%25AE/" rel="tag">位置</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/csharp-asp-net-webform-print-need-noneed/#blogcomment</link>
<title><![CDATA[[评论] c#实现web页面打印,可以控制需要打印和不需要打印的位置]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/csharp-asp-net-webform-print-need-noneed/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>