Print Div Content Only In ASP.NET

There are times when developers want to print a specific area of a web page such as a Div content.
 
Step 1. Give your DIV that you want to print an ID. Everything placed inside that DIV will also be printed.
 
Example:
  1. <div id="abc"> hello sir</div>  
Step 2. Add the following JavaScript code anywhere in your <html> section. This code is a print function that finds the DIV using document.getElementById. Creates a print window and prints it.
  1. <script type="text/javascript">  
  2. <!--  
  3. function printPartOfPage(elementId) {  
  4. var printContent = document.getElementById(elementId);  
  5. var windowUrl = 'about:blank';  
  6. var uniqueName = new Date();  
  7. var windowName = 'Print' + uniqueName.getTime();  
  8. var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');  
  9. printWindow.document.write(printContent.innerHTML);  
  10. printWindow.document.close();  
  11. printWindow.focus();  
  12. printWindow.print();  
  13. printWindow.close();  
  14. }  
  15. // -->  
  16. </script>  
Step 3. Place a button on the page and call the print function. You can call the same function any where you need to print a DIV content.
  1. <input type="button" value="Print" onclick="JavaScript:printPartOfPage('abc');"/>  
Here is a more detailed article, Print DIV Content of a Page using JavaScript