This is a discussion on How Create print preview page dynamically in ASP.NET within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, I want to show a print preview page before printing the page, then I have to make a page ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, I want to show a print preview page before printing the page, then I have to make a page like that currently is showing. and I want to print a particular section of that page like only Data Grid, HTML Table, or any others section. How to do this ? Thanks KiruthikaSambandam |
| Sponsored Links |
| |||
|
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
| |||
| hi check this link. it really helps u. CodeProject: Creating print preview page dynamically in ASP.NET. Free source code and programming help |
| |||
| function getPrint(print_area) { //Creating new page var pp = window.open(); //Adding HTML opening tag with <HEAD> … </HEAD> portion pp.document.writeln('<HTML><HEAD><title>Print Preview</title>') pp.document.writeln('<LINK href=Styles.css type="text/css" rel="stylesheet">') pp.document.writeln('<LINK href=PrintStyle.css type="text/css" rel="stylesheet" media="print">') pp.document.writeln('<base target="_self"></HEAD>') //Adding Body Tag pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"'); pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">'); //Adding form Tag pp.document.writeln('<form method="post">'); //Creating two buttons Print and Close within a HTML table pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>'); pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" '); pp.document.writeln('onclick="javascript:location. reload(true);window.print();">'); pp.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">'); pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>'); //Writing print area of the calling page pp.document.writeln(document.getElementById(print_ area).innerHTML); //Ending Tag of </form>, </body> and </HTML> pp.document.writeln('</form></body></HTML>'); } 'calling getPrint() function in the button onclick event btnPrint.Attributes.Add("Onclick", "getPrint('print_area');") btnTablePP.Attributes.Add("Onclick", "getPrint('Print_Table');") btnPagepp.Attributes.Add("Onclick", "getPrint('Print_All');") |
| |||
| <script type="text/javascript"> var gridViewCtlId = '<%=GridView.ClientID%>'; function Print() { //assuming that this is the generated ID var grid_obj = document.getElementById(gridViewCtlId); if (grid_obj != null) { var new_window = window.open('print.html'); //print.html is just a dummy page with no content in it. new_window.document.write(grid_obj.outerHTML); new_window.print(); new_window.close(); } } </script> You could also comment out the print() and close(), this way user will have a ‘print preview’ and has the chance to set margin, header/footer of the print out.
__________________ Shaalini.S ![]() Be the Best of Whatever you are... Last edited by shaalini : 03-21-2008 at 04:53 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can we Dynamically create web controls | Kirubhananth | ASP and ASP.NET Programming | 3 | 03-14-2008 10:00 PM |
| Code-behind to create node dynamically using XML File or any Stored Procedure | poornima | ASP and ASP.NET Programming | 3 | 02-14-2008 09:46 PM |
| Preview Image before Uploading File to Server | velhari | HTML, CSS and Javascript Coding Techniques | 1 | 11-12-2007 10:21 PM |
| Create database object with dynamically | S.Vinothkumar | C# Programming | 6 | 09-28-2007 11:49 PM |
| how to print iframe pdf document using file print menu using javascript | kingmaker | HTML, CSS and Javascript Coding Techniques | 1 | 08-22-2007 05:32 AM |