954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to print specified contents in .NET 2.0?

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();
}


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

bhavna_816
Junior Poster
116 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

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.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You