How to print the fixed area of webpage ?



Hi

Here is the javscript code to do this task

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
<title></title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<div id="Div1" style="background-color:Silver; border:2px; height:200px; width:500px; border:2px; border-color:Red; border-style:solid">
Printable content
</div>

<script type="text/javascript">
<!–
function printPartOfPage(elementId)
{
var printContent = document.getElementById(elementId);
var windowUrl = ‘about:blank’;
var uniqueName = new Date();
var windowName = ‘Print’ + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, ‘left=5000,top=5000,width=0,height=0’);

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

<asp:Button ID="Button1" runat="server" Text="Print" onclientClick="JavaScript:printPartOfPage(‘Div1’);" />

</form>
</body>
</html>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.