I want to print the page in C#/ASP.NET 2.0, but the problem is when i use following javascript code, it prints the whole page.

function printMe()
document.getElementById("printed").value = "YES";
<form id="form1" runat="server">

<input type="button" value="Print me" onclick="printMe();" />
<input type="hidden" id="printed" />

I don't want to print the complete page but i just want to print the contents of the page only.
Do anybody have any idea?

Thanks in advance

9 Years
Discussion Span
Last Post by hollystyles

You have a couple of choices depending on how many elements you require to print. There is no 'builtin' solution for this kind of thing in ASP.NET

look into CSS

<style type="text/css" media="print">#elementid {display; none;}</style>

You can have a separate style sheet for the browser to apply when printing, which hides any elements you don't want in the print out, by applying display: none style to them.

The other option is appending the elements you want printed into an iFrame thats positioned out of site in the page and print from that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.