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()
{
window.print();
document.getElementById("printed").value = "YES";
document.getElementById("form1").submit();
}
<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

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.