<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintDiv.aspx.cs" Inherits="PrintDiv" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script language="javascript">
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,toolbar=1,scrollbars=1,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
</script>
<div id="print_Grid">
This is Print This is Print This is Print This is Print This is Print
<div>
<asp:Button ID="btnPrint" runat="server" Text="Print" />
</form>
</body>
</html>
using System;
public partial class PrintDiv : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnPrint.Attributes.Add("onclick", "javascript:CallPrint('print_Grid')");
}
}
For More Information Visit : http://rajeshprajapati.blogspot.in/2009/05/how-to-print-div-tag-using-javascript.html
Rajesh Prajapati
My Blog My Website Please contact prajapati.rajesh@gmail.com
rbprajapati
Member
30 Points
21 Posts
Re: How to do custom printing in asp.net?
Feb 25, 2012 03:57 AM|LINK
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintDiv.aspx.cs" Inherits="PrintDiv" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <script language="javascript"> function CallPrint(strid) { var prtContent = document.getElementById(strid); var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,toolbar=1,scrollbars=1,status=0'); WinPrint.document.write(prtContent.innerHTML); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); prtContent.innerHTML = strOldOne; } </script> <div id="print_Grid"> This is Print This is Print This is Print This is Print This is Print <div> <asp:Button ID="btnPrint" runat="server" Text="Print" /> </form> </body> </html> using System; public partial class PrintDiv : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { btnPrint.Attributes.Add("onclick", "javascript:CallPrint('print_Grid')"); } } For More Information Visit : http://rajeshprajapati.blogspot.in/2009/05/how-to-print-div-tag-using-javascript.htmlMy Blog
My Website
Please contact prajapati.rajesh@gmail.com