Today I was Explaining How to Print Specific Area in Asp.net web page .
So here I am just adding one more search result for Google.
In previous posts, I was explained about how to Get List of All Table Names in Database and COLLATE keyword , ListView with group headers .
In previous posts, I was explained about how to Get List of All Table Names in Database and COLLATE keyword , ListView with group headers .
There are two different ways to do like this
One way use the Css like bellow
You can't print a specific area of a page, but you can hide the rest of the page when printing. Create a CSS that hides the element that you don't want to print:
@media print {
.someelement, .otherelement, .morelement { display: none; }
}
Another way Use the java script for printing
<script language="javascript" type="text/javascript">
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=800,height=100,toolbar=0,scrollbars=0,status=0,dir=ltr');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
</script>
and call it from button
<asp:button id="BtnPrint" runat="server" onclientclick="javascript:CallPrint('bill');" text="Print" xmlns:asp="#unknown" />
Please Note that your div also should has name (bill)
Sample Example
One way use the Css like bellow
You can't print a specific area of a page, but you can hide the rest of the page when printing. Create a CSS that hides the element that you don't want to print:
@media print {
.someelement, .otherelement, .morelement { display: none; }
}
Another way Use the java script for printing
<script language="javascript" type="text/javascript">
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=800,height=100,toolbar=0,scrollbars=0,status=0,dir=ltr');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
</script>
and call it from button
<asp:button id="BtnPrint" runat="server" onclientclick="javascript:CallPrint('bill');" text="Print" xmlns:asp="#unknown" />
Please Note that your div also should has name (bill)
Sample Example
You can use a print style sheet, which sets the display property on everything except what you want printed to none.
You can load different style sheets for different media using the media attribute.
style.css:
#header
{
background-color: #ccc;
font-size: 2em;
height: 4em;
clear: both;
}
print.css:
#header
{
display: none;
}
yourpage.aspx:
<head>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
</head>
<body>
<div id="header">My Site!</div>
<div id="content">
Only print me
</div>
</body>
You can load different style sheets for different media using the media attribute.
style.css:
#header
{
background-color: #ccc;
font-size: 2em;
height: 4em;
clear: both;
}
print.css:
#header
{
display: none;
}
yourpage.aspx:
<head>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
</head>
<body>
<div id="header">My Site!</div>
<div id="content">
Only print me
</div>
</body>
Comments
Post a Comment