Thursday, May 14, 2009

How to Print Div Tag Using Javascript?



HTML FILE :

<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>



Code FILE :


protected void Page_Load(object sender, EventArgs e)

{

btnPrint.Attributes.Add("onclick", "javascript:CallPrint('print_Grid')");

}


How To Use This Code?

1. Copy JavaScript into your HTML Page

2. Make a Div Tag Which data you want to print into that div tag

3. Add Print Button and call JavaScript Function




No comments:

ShareThis

Welcome

Welcome to Rajesh Prajapati, asp.net blog.
Here you can find some useful code and information about asp.net., c#, VB.net, SQL Server, Web Service, Web Designing etc