Print Preview.zip (11.73 kb)
Printing and previewing web page is a common requirement for a web application. The tranditional way of launching a printable version of the form is by using a popup window or sometimes a simple redirect to printable version of the page. This allows the user to preview and print a version of the page without the header and footer, ads, company logo, colorfull graphics, and other printing overheads to save resources (printer ink, paper, etc).
One trick to do this without redirecting or launching a pop-up window is through using <link> tag. Just add a link tag and set the media attribute to print, rel attribute to alternate, and set the href to the path of the printable version of the page then you are done. After adding the link tag, try previewing the page using File | Print Preview menu of your IE browser. In preview window you should see the printable verstion page instead of the current page.
Snippets
<link rel="alternate" media="print" href="Print.aspx?id=1" />
I added a query string in href to show that it is possible to provide it to dynamically load content and to reuse the template to other pages.
The major disadvantage of this approach is that it is only supported IE 6.0 or later browser :(.
Attached is the sample code which includes static and dynamic version.
Cheers!
Rod