The process is simple:
First in the ASP.net page, set the mark to start printing and finish printing, in order to ensure that the tag does not appear when browsing the page, we adopt the "<!--HTML annotation-->" approach. such as:<!--startprint--> and <!--endprint-->.
Then write the relevant JavaScript code, the specific code to see after.
If you do not want the Print button to be printed, note that the Print button is included outside the <!--startprint--> and <!--endprint-->.
Related code:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "AppealPrint.aspx.cs" inherits= "Appeal.appealprint"
Masterpagefile= "Masterpage.master" title= "appeal print"%>
<asp:content id= "Content1" contentplaceholderid= "cphnavigation" runat= "Server" >
</asp:Content>
<asp:content id= "Content2" contentplaceholderid= "cphcontent" runat= "Server" >
<!--startprint-->
<style type= "Text/css" >
body,table{
font-size:12px;
}
table{
table-layout:fixed;
Empty-cells:show;
Border-collapse:collapse;
margin:0 Auto;
}
td{
height:20px;
}
h1,h2,h3{
font-size:12px;
margin:0;
padding:0;
}
table{
border:1px solid #cad9ea;
Color: #666;
}
Table th{
height:30px;
}
Table Td,table th{
border:1px solid #cad9ea;
padding:0 1em 0;
}
Table tr{
Background-color: #f5fafe;
}
</style>
<table class= "Border" cellspacing= "0" cellpadding= "2" style= "margin:0px auto; width:98%;border:1px solid;border-collapse:collapse; "id=" Tabbtnprint ">
<tbody>
<TR align= "center" >
<TD class= "title" ><strong> Appeal information </strong></td>
</tr>
<tr>
<TD style= "height:25px" >
<table cellspacing= "1" cellpadding= "2" style= "margin:0px auto; Width:100%;border-collapse:collapse; " >
<tbody>
<tr class= "tdbg" >
<TD width= "30%" align= "right" nowrap= "nowrap" > Appeal theme:</td>
<TD colspan= "3" >
<asp:label id= "Lbledittitle" runat= "Server" text= "Label" ></asp:Label>
</td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" width= "30%" nowrap= "nowrap" > Appeal type:</td>
<TD colspan= "3" >
<asp:label id= "lblappealcategory" runat= "Server" text= ""/>
</td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" width= "30%" nowrap= "nowrap" > Appeal current status:</td>
<TD colspan= "3" >
<asp:label id= "lblstatus" runat= "Server" text= "Label"/>
</td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > Appeal Nature:</td>
<TD style= "width:15%" ><asp:label id= "lblappealnature" runat= "Server" text= "Label"/></td>
<TD align= "Right" style= "width:25%" nowrap= "nowrap" > The name of the complainant:</td>
<TD style= "width:30%" ><asp:label id= "Lblbeappealname" runat= "Server" text= "Label"/></td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > The complainant's address:</td>
<TD style= "width:15%" ><asp:label id= "lblbeappealaddress" runat= "Server" text= "Label"/></td>
<TD align= "Right" style= "width:25%" nowrap= "nowrap" > Complainant:</td>
<TD style= "width:30%" ><asp:label id= "Lblusername" runat= "Server" text= "Label"/></td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > Appeal information is confidential:</td>
<TD style= "width:15%" ><asp:label id= "Lblissecret" runat= "Server" text= "Label"/></td>
<TD align= "Right" style= "width:25%" nowrap= "nowrap" > Admin agree to open:</td>
<TD style= "width:30%" align= "right" ><asp:label id= "lbladminispublic" runat= "Server" text= "Label"/></ Td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > Browse number:</td>
<TD style= "width:15%" ><asp:label id= "lblhits" runat= "Server" text= "Label"/></td>
<TD align= "Right" style= "width:25%" nowrap= "nowrap" > Reply number:</td>
<TD style= "width:30%" ><asp:label id= "lblreply" runat= "Server" text= "Label"/></td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > Archive:</td>
<TD style= "width:15%" ><asp:label id= "lblcategory" runat= "Server" text= ""/></td>
<TD align= "Right" style= "width:25%" nowrap= "nowrap" > Appeal submission Time:</td>
<TD style= "width:30%" ><asp:label id= "Lblcreatetime" runat= "Server" text= "Label"/></td>
</tr>
<tr class= "tdbg" >
<TD align= "Right" style= "width:30%" nowrap= "nowrap" > Appeal region:</td>
<TD colspan= "3" ><asp:label id= "lblregion" runat= "Server" text= "" ></asp:Label></td>
</tr>
<tr class= "tdbg" >
<TD colspan= "4" ><asp:label id= "Label2" runat= "Server" text= ""/></td>
</tr>
<tr class= "tdbg" >
<TD colspan= "4" align= "left" valign= "the Top" nowrap= "nowrap" > Appeal content:</td>
</tr>
<tr class= "tdbg" >
<TD colspan= "4" align= "left" valign= "Top" >
<pe:extendedliteral id= "ltreditcontent" runat= "Server" htmlencode= "false"/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!--endprint-->
<br/>
<div id= "Divbtnprint" style= "Text-align:center" >
<input id= "btnprint" type= button "value=" Print ... "onclick=" doprint (); "/>
</div>
<br/>
<script type= "Text/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;
var obj = window.document.body;
dozoom (obj, 18);//Enlarge printing
Window.print ();
}
function Dozoom (artibody, size) {
if (!artibody)
{
Return
}
Setchildnodesbycurrentnode (artibody,size);
}
function Setchildnodesbycurrentnode (node,size) {
for (Var i=0 i < node.childNodes.length; i++) {
var artibodychild = node.childnodes[i];
if (Artibodychild.nodetype = = 1) {
Artibodychild.classname= "";
artibodyChild.style.fontSize = size + ' px ';
artibodyChild.style.fontFamily = ' Imitation _gb2312, song Body, ' Times New Roman ', Georgia,serif ';
ArtibodyChild.style.fontWeight = 900;
if (artibodychild.childnodes.length>0) {
Setchildnodesbycurrentnode (artibodychild,size);
}
}
}
}
-->
</script>
</asp:Content>
Looking at the above code, you can see that when printing, the Window.document.body.innerHTML is assigned to the code that sets the portion of the page that needs to be printed (this is prnhtml), Setchildnodesbycurrentnode (artibody,size) is then invoked recursively to change the style of the associated child nodes to replace the associated font size and style settings for all.