Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Friday, November 29, 2013

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>