Follow by Email

Friday, August 23, 2013

hi in this post i will show how to print a particular <div> section using JavaScript in asp.net.

Example:

<script type="text/javascript">
    function ClickToPrint() {
        docPrint = window.open("", "Print");
        docPrint.document.open();
        docPrint.document.write('<html><head><title>::PRINT SAMPLE::</title>');
        docPrint.document.write('</head><body onLoad="self.print()">');
        docPrint.document.write('<table width="900px" border=0><tr><td width=100%><center><font face="windings">');
        docPrint.document.write(document.getElementById("PrintDiv").innerHTML);
        docPrint.document.write('</font></center></td></tr></table></body></html>');
        docPrint.document.close();
    }

</script>
<html>
<head runat="server">
    <title></title>
</head>
<body>
    <div id="PrintDiv">
        Hello World ! This is Asp.net.
    </div>
    <div id="DoNotPrintDiv">
        Thanks for visiting this website !!
    </div>
    <input id="Button1" onclick="ClickToPrint();" type="button" value="Print" class="button" />
</body>
</html>