Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to give print of my web page.
But it has 1 gridview,1 Treeview, 3 Button ,3 Images,Header & Footer Controls.
I want to remove all the above mentioned controls.I want remain my print content only.
& the main thing is that it has master page content.
So how to remove all the controls in my web page & how to give the print of the web page.

Thanks in Advance,
VenkiDesai.
Posted

Create a "print.css" stylesheet which hides all the elements you don't want to print. And add it with a media="print"
HTML
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
</link>


In that file (print.css) you hide all elements that you don't want to print.
CSS
#header {display:none;}
#footer {display:none;}

/* hide my treeview */
.treeview {display:none;}

/* hide my grids */
.grid {display:none;}
/* Hide all buttons, dropdowns etc. */
input, select, textarea {display:none;}


You will of course have to set some classes to your grid's, treeview's etc. Or you can just add a "noprint" class to all elements which should not be printed. In that case you can just add this to your print.css

CSS
.noprint {display:none;}
 
Share this answer
 
v3
Comments
bbirajdar 10-Aug-12 9:40am    
Excellelnt solution +5
StianSandberg 10-Aug-12 9:41am    
thank you :) it's clean and easy to maintain
Sergey Alexandrovich Kryukov 10-Aug-12 16:44pm    
Agree; this is a clean non-obtrusive solution. I only wish Web browser layout engines finally implemented media and page CSS correctly. The buttons on a Web page, like "Print" is mostly just lame. My 5.
--SA
your css file should has 2 parts
CSS
@media screen
{
    .button
    {
        
    }
}
@media print
{
    .button
    {
         display: none;
    }
}
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 10-Aug-12 16:45pm    
I disagree with the vote of 1; I voted 5. This is the right idea. (Well, you could provide more detail explanation and links though.) I only wish Web browser layout engines finally implemented media and page CSS correctly. The buttons on a Web page, like "Print" is mostly just lame.
--SA
[no name] 10-Aug-12 17:27pm    
Thank you Sergey.
I wish people like you always survive me from bad voting.
My three answers has been down voted at a second; however my answers are not really deserve that.
Dear Friend for this you Should use JavaScript

JavaScript
<script type="text/javascript" language="javascript">
function getPrint(print_area) {

    var disp_setting = "toolbar=false,location=no,directories=yes,menubar=false,";
    disp_setting += "scrollbars=yes,width=880, height=600, left=100, top=25";
    var content_vlue = document.getElementById("print_area").innerHTML;
    var str = "UGANDA EMIS II PROJECT ICT INFRASTRUCTURE NEEDS ASSESSMENT IN EDUCATION & SPORTS SECTOR";
    var docprint = window.open("", "", disp_setting);
    docprint.document.writeln(str.bold());
    docprint.document.writeln('<base target="_self">')
    //Adding Body Tag
    docprint.document.writeln('<body ms_positioning="GridLayout" bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0">');
    //Adding form Tag
    docprint.document.writeln('<form method="post">');
    //Creating two buttons Print and Close within a table

    docprint.document.writeln('<input id="PRINT" type="button" value="Print"  önclick="javascript:location.reload(false);window.print();"><input id="CLOSE" type="button" value="Close"  önclick="window.close();">');
    //Writing print area of the calling page
    docprint.document.writeln(document.getElementById(print_area).innerHTML);
    //Ending Tag of </input></input></form>, </body> and 
    docprint.document.writeln('');
}
</base></script>

and in BUTTON EVENT
u SHOULD CALL THE Print Function.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900