Subscribe to Subscribers

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




Responses

#357461    Author: Deepika Haridas      Member Level: Gold      Member Rank: 7     Date: 19/Mar/2009   Rating: 2 out of 52 out of 5     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.



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

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.