944,162 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 44316
  • ASP.NET RSS
Sep 13th, 2006
0

Print a web page in ASP.net

Expand Post »
Hi, I have a web page which is developed using ASP.net code behind is VB.net. I want to print the page by clicking HTML button control but I dont want to print the print button control which is there in web page. I tried with window.print() but it is printing the control also. please help me out. thanks in advance.

Raju
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raju5725 is offline Offline
15 posts
since Sep 2006
Sep 13th, 2006
0

Re: Print a web page in ASP.net

You need to handle visibility of the object by using CSS media styles. If you dont want your button (or any object on page) to print add this code to your CSS styles:

ASP.NET Syntax (Toggle Plain Text)
  1. @media print
  2. {
  3. .PrintButton{
  4. display:none;
  5. }
  6. }
  7.  
  8. @media screen
  9. {
  10. .PrintButton{
  11. display:block;
  12. }
  13. }

and attach this class to yout button like:

[html]<input id="btnPrint" class="PrintButton" />[/html]
Last edited by ManicCW; Sep 13th, 2006 at 3:34 am.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Sep 14th, 2006
0

Re: Print a web page in ASP.net

Thanks for the response, I tried but I am getting the HTMLButton Control on my printed page, can you give me some more clarity.

Raju5725

Click to Expand / Collapse  Quote originally posted by ManicCW ...
You need to handle visibility of the object by using CSS media styles. If you dont want your button (or any object on page) to print add this code to your CSS styles:

ASP.NET Syntax (Toggle Plain Text)
  1. @media print
  2. {
  3. .PrintButton{
  4. display:none;
  5. }
  6. }
  7.  
  8. @media screen
  9. {
  10. .PrintButton{
  11. display:block;
  12. }
  13. }

and attach this class to yout button like:

[html]<input id="btnPrint" class="PrintButton" />[/html]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raju5725 is offline Offline
15 posts
since Sep 2006
Sep 14th, 2006
0

Re: Print a web page in ASP.net

It has to work! Here is the code I have just tested and it works, I have tested it on IE, Firefox, Opera. I have put styles in the same document for clarity.

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hide print button</title>
<style type="text/css" media="screen">
.PrintButton{
display:block;
}
</style>
<style type="text/css" media="print">
.PrintButton{
display:none;
}
</style>
</head>
<body>
<form id="PrintForm" action="Print.htm">
<h1>
Test printing with hiden button</h1>
This is just a test text for printing.<br />
<br />
<input id="btnPrint" type="button" value="Print page" class="PrintButton" onclick="window.print();" />
</form>
</body>
</html>
[/HTML]

This is code for the entire page. Try it, it works.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: SQL Server, Images and DataGrid in ASP.NET
Next Thread in ASP.NET Forum Timeline: Atlas is dead: long live ASP.NET 2.0 AJAX Extensions...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC