How to print a particular div in asp.net c# using JQuery
How to print a particular div in asIn this article, we learn how to print a particular div or panel in asp.net using Jquery. As we can see below we have created a panel with the name pnlContents and we will print all the values inside of pnlContents panel.
Source Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
In this article, we learn how to print
a particular panel in asp.net c# using jquery.
<asp:Panel ID="pnlContents" runat="server">
<p style="font-size:
11pt; font-weight: bold; font-family: 'Times New Roman'">
Hello Friends,
C# is a simple, modern, general
purpose programming language. It is an object oriented programming
<br />
language developed by Microsoft. It
is a safe and managed language that is compiled by
<br />
.NET framework to generate
Microsoft intermediate language (machine code).<br />
<br />
C# is designed for Common Language
Infrastructure (CLI). It contains the executable code and<br />
runtime environment that makes the
users able
<br />
to use various high-level languages
on different computer platforms and architectures.
</p>
</asp:Panel>
<br />
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="return
PrintPanel();" />
</form>
</body>
<script type="text/javascript">
function
PrintPanel() {
var
panel = document.getElementById("<%=pnlContents.ClientID
%>");
var
printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>PARTICULAR
DIV PRINT OUT</title>');
printWindow.document.write('</head><body
>');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function ()
{
printWindow.print();
}, 500);
return false;
}
</script>
</html>
Out-put:-
No comments: