ASP.NET - Print Only the Content Inside of Div

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, but the maximum is either using IFrame or the Window.open() popup and then using window.print() to print 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

Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Ed Price MSFT edited Original. Comment: Cleaning this up.

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (3 items)