ASP.NET - Print Only the Content Inside of Div

Requirement: Print only the content inside of Div in ASP.NET.

Solution:
For printing the page, there is a Javascript function: window.print(). However, it will print the whole page. If you need to print only the content of Div, then you have a few options available.  Amongst these one can either using IFrame or the Window.open() popup and then window.print() on the div content.

You can use JavaScript to open div content in a popup and then print it. See this solution here:
http://geekiest.net/post/Print-the-content-of-a-div-using-JavaScript.aspx

Another option is to use IFrame. See more about that here:
http://www.isolutionteam.co.uk/printing-contents-of-a-div-using-javascript/

The recommended option is to use JQuery:
http://www.bennadel.com/index.cfm?event=blog.viewcode&id=1591&index=1
It uses the jquery.print.js plugin and works great.

This article was originally written by Jayant.

 

Community Resources

See Also