How to Print Div in Asp.net Programming by javaScript

How to Print Div in Asp.net Programming by java Script



Print Div in asp.net is use when the developer want to print a particular part of web page.we can use java script for this work.the code is given here.....


var divToPrint = document.getElementById('MYDIV');
           var popupWin = window.open('', '_blank', 'width=700,height=500');
           popupWin.document.open();
           popupWin.document.write('<html><head><title>Student Attendance   
           Report</title><body onload="window.print()">' + divToPrint.innerHTML +
           '</html>');

JavaScript code for Print button:

<script type="text/javascript" language="javascript">
       function PrintDiv()
 {
           var divToPrint = document.getElementById('MYDIV');
           var popupWin = window.open('', '_blank', 'width=700,height=500');
           popupWin.document.open();
           popupWin.document.write('<html><head><title>Student Attendance   
           Report</title><body onload="window.print()">' + divToPrint.innerHTML +
           '</html>');
           popupWin.document.close();
       }
         </script>




Print button:

                      

<input id="btnPrint" runat="server" type="button" value="Print" visible="false" nclick="PrintDiv()" />



DIV:

  <div id="MYDIV"> 
</div>

Popular posts from this blog