Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Online Members
Kapil
More...
Forums
»
.NET
»
ASP.NET
»
Print problem
Posted Date:
19 Mar 2009
Posted By::
YuDi
Member Level:
Gold
Member Rank:
114
Points
: 1
Responses:
1
how to print the content palace holder's data in A4 size paper
please give me code to print.
and also give me all options that means all types of printing page data.
thanks
“Talent wins games, but teamwork and intelligence wins championships.”
umardaraj07@gmail.com
Tweet
Responses
#357461 Author:
Deepika Haridas
Member Level:
Gold
Member Rank:
7
Date: 19/Mar/2009 Rating:
Points
: 2
Hi,
Try this you wanted to print your Content Place holder's data.
So try this
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
/// <summary>
/// Summary description for PrintWebControl_Test
/// </summary>
public class PrintWebControl_Test
{
public PrintWebControl_Test()
{
//
// TODO: Add constructor logic here
//
}
public static void PrintWebControl(Control ctrl)
{
PrintWebControl(ctrl, string.Empty);
}
/// <summary>
/// Prints any Control i.e. User Control, DataGrid,Repeater, Page , Panel etc.
/// </summary>
/// <param name="ctrl">Control to be printed</param>
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(50, UnitType.Pixel);
((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.RegisterStartupScript("PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
string scr = "<script>function window.onafterprint(){history.back(1);}</script>";
htmlWrite.Write(scr);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
public static void PreviewWebControl(Control ctrl)
{
PreviewWebControl(ctrl, string.Empty);
}
/// <summary>
/// Prints any Control i.e. User Control, DataGrid,Repeater, Page , Panel etc.
/// </summary>
/// <param name="ctrl">Control to be printed</param>
public static void PreviewWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(50, UnitType.Pixel);
((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.RegisterStartupScript("PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
string scr = "<script>function window.onafterprint(){history.back(1);}</script>";
htmlWrite.Write(scr);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
}
Thanks & Regards,
Deepika
-
Sr. Editor
Webmaster, GujaratSpider
http://angeldeeps.blogspot.com/
"Experience is the name everyone gives to his mistakes"
GujaratSpider - Post and Earn
Post Reply
This thread is locked for new responses. Please post your comments and questions as a
separate thread
.
If required, refer to the URL of this page in your
new post
.
Tweet
Next :
How to store checkbox value to sql database if it checked using c#
Previous :
To dipika hardis
Return to Discussion Forum
Post New Message
Category:
Related Messages
Validation Controls
no of click on advertisement in asp.net application
Please Please help.................. tooo urgent
Please tell me .Net interview Questions for 2+ Years Exp
To upload Documents like(doc,pdf,etc) to file system
Active Members
Today
Pawan Awasthi
(46)
naveensanagase...
(21)
Kapil
(13)
Last 7 Days
naveensanagase...
(224)
Pawan Awasthi
(190)
Naved Hasan ...
(189)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds
Talk to Webmaster Tony John