| | |
Print a web page in ASP.net
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2006
Posts: 15
Reputation:
Solved Threads: 0
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
Raju
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:
and attach this class to yout button like:
[html]<input id="btnPrint" class="PrintButton" />[/html]
ASP.NET Syntax (Toggle Plain Text)
@media print { .PrintButton{ display:none; } } @media screen { .PrintButton{ display:block; } }
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.
•
•
Join Date: Sep 2006
Posts: 15
Reputation:
Solved Threads: 0
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
Raju5725
•
•
•
•
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)
@media print { .PrintButton{ display:none; } } @media screen { .PrintButton{ display:block; } }
and attach this class to yout button like:
[html]<input id="btnPrint" class="PrintButton" />[/html]
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.
[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.
![]() |
Similar Threads
- How to print the items in a datagrid in ASP .Net (ASP.NET)
- How To Hyperlink Normal HTML page with ASP.NET Page? (ASP.NET)
- advice about final year project using ASP.net (ASP.NET)
- Web Service with ASP .Net (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: SQL Server, Images and DataGrid in ASP.NET
- Next Thread: Atlas is dead: long live ASP.NET 2.0 AJAX Extensions...
Views: 22052 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 activexcontrol advice ajax application asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn chat checkbox child class click compatible confirmationcodegeneration content contenttype countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdown dropdownmenu edit feedback flash flv folder form forms google grid gridview homeedition hosting identity iframe iis index javascript jquery list menu mono mssql multistepregistration nameisnotdeclared object objects order problem profile ratings refer rotatepage save search security serializesmo.table session silverlight smartcard software sql suse textbox tracking typeof unauthorized update validation vb vb.net video view virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt wizard xml





