In this post, I will explain How to Print Panel Content in Asp.Net using JavaScript.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrintPanel.aspx.cs" Inherits="TestApplication.PrintPanel" %>
<!DOCTYPE html>
<html lang="">
<head>
<title>Print Panel Content in Asp.Net using JavaScript</title>
<script type="text/javascript">
// JavaScript function to print data
function PrintPanelData() {
// panel to print data
var panel = document.getElementById("<%=pnlDetails.ClientID %>");
// Create a web page with panel content
var printData = window.open('', '', 'height=500, width=1000');
printData.document.write('<html><head><title>Panel Data</title>');
printData.document.write('</head><body >');
printData.document.write(panel.innerHTML);
printData.document.write('</body></html>');
printData.document.close();
// Open popup window and gives print dialogue box to print content
setTimeout(function () {
printData.print();
}, 20);
return false;
}
</script>
</head>
<body>
<form runat="server">
<asp:Panel ID="pnlDetails" runat="server">
<p style="font-size: 12pt; font-family: 'Times New Roman'">
Blogger is a blog-publishing service that allows multi-user blogs with time-stamped entries. It was developed by Pyra Labs, which was bought by Google in 2003.
</p>
<p style="font-size: 12pt; font-family: 'Times New Roman'">
Generally, the blogs are hosted by Google at a subdomain of blogspot.com. Blogs can also be hosted in the registered custom domain of the blogger (like www.example.com).
</p>
<p style="font-size: 12pt; font-family: 'Times New Roman'">
[4] A user can have up to 100 blogs per account.
</p>
</asp:Panel>
<br />
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="return PrintPanelData();" />
</form>
</body>
</html>
0 comments:
Post a Comment
Please do not enter any spam link in the message box.