Print a web page in ASP.net

Reply

Join Date: Sep 2006
Posts: 15
Reputation: Raju5725 is an unknown quantity at this point 
Solved Threads: 0
Raju5725 Raju5725 is offline Offline
Newbie Poster

Print a web page in ASP.net

 
0
  #1
Sep 13th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Print a web page in ASP.net

 
0
  #2
Sep 13th, 2006
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 15
Reputation: Raju5725 is an unknown quantity at this point 
Solved Threads: 0
Raju5725 Raju5725 is offline Offline
Newbie Poster

Re: Print a web page in ASP.net

 
0
  #3
Sep 14th, 2006
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

Originally Posted by ManicCW View Post
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:

  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]
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Print a web page in ASP.net

 
0
  #4
Sep 14th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 22052 | Replies: 3
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC