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 can achieve this from code
behind file too as per 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" />

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 =, windowName, 'width=1024pt');


here Div2 div holds the can place any data control like
GridView and populate in page load 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 3307 times
Super User

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

Latest discussions

  • No posts to display.