Hide header information on print of aspx page

kdeutsch
kdeutsch used Ask the Experts™
on
I am trying to change the print process because of additional requirements, which forces me to move to code behind page.  What i need to do is hide the header information on the page via the code behind the first code is the way i do it currenlty but I am going to use a link button that prints the page from code behind, but I can't seem to hide the top of page on print.

Current way of printing aspx page.
<body onload="javascript:loadHeader('State Active Duty', 'SAD Pay Certification', '1|');"
		style="MARGIN: 0px; FONT-FAMILY: arial" onbeforeprint="document.getElementById('headTbl').style.display='none';document.getElementById('button1').style.display='none';"
		onafterprint="document.getElementById('headTbl').style.display='inline';document.getElementById('button1').style.display='inline';">


<tr>
					<td align="center"><input type="button" value="Print" onclick="window.print()" id="button1" runat="server"
							name="Print"></td>
				</tr>

New way
<tr>
					<td align="center"><asp:LinkButton ID="lnkPrint" Runat="server">Print</asp:LinkButton></td>
				</tr>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Why not just use a printer style sheet which has "display:none;" on a div containing the header.  Reference the stylesheet file like this:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

Author

Commented:
ChetOS82:
Well dont' know if this project still being in asp.net 1.1 makes a difference but you will have to explain more because don't use style sheets.
Commented:
More information: http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml

First: Remove the onbeforeprint and onafterprint attributes from the body tag.
Second: create a file in the same directory as the page called "print.css".
It looks like the ID of the header is "headTbl", and that you also want to hide the button (button1) when you print.  I am ignoring that LinkButton because I have no idea what you are doing with it.

In the print.css file put:
#headTbl {display:none;}
#button1 {display:none;}

Third: in the <head> tag of your web page, put the following line:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

Ok, now you should be able to do print preview (or print the page) and see that the header has been removed.  Since the browser is handling this natively now, you don't even need to provide print buttons because the user can use the browser's print button.

Author

Commented:
ChetOS82:
ok thanks I will try it out and let you know how it goes.

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial