Print this page
Wednesday, 23 January 2013 13:56

how to print a part of page

Written by 
Rate this item
(0 votes)

it is easier to print part of page.the part of the page
may be under a div or panel.you can achieve this from code
behind file too as per requirement.here i showing only
in page lavel -

here are the page html codes -

<span onclick="javascript:printPartOfPage('Div2')">Print</span>

<div id="Div2" style="width:1024px;">
<asp:Label ID="ScInfo" runat="server" Font-Size="10pt" /><br />
<asp:Label ID="dataPreviewLabel" Font-Size="8pt" runat="server" />
</div>

and the javascript function is as follows -

<script type="text/javascript">
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var date = new Date();
var windowName = 'Print' + date.getTime();
var printWin = window.open(windowUrl, windowName, 'width=1024pt');

printWin.document.write(printContent.innerHTML);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}
</script>

here Div2 div holds the data.you can place any data control like
GridView and populate in page load event.in the above code
when Print text clicked it calls the javascript function
printPartOfPage('Div2') by supplying the data div as a parameter
to be printed

Read 3249 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
7