Showing posts with label How to Print a Control. Show all posts
Showing posts with label How to Print a Control. Show all posts

Saturday, February 6, 2010

How to Print a Panel

First do the necessary at server then save the control Panel in the session at Page MainPage.aspx

protected void btn_Click(object sender, EventArgs e)
{
Session["Ctrl"] = pnlContainer;//Panel ID
Response.Redirect("print.aspx");
}


Create a new page with the print.aspx, Html Code as follows:


Add Content PlaceHolder to html with name ph

"<asp:PlaceHolder ID="ph" runat="server" /&gt

And print.aspx.cs code is follows:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["Ctrl"] != null && Session["Ctrl"].ToString() != "")
Ph.Controls.Add((Panel)Session["Ctrl"]);
}
else
{
Response.Redirect("MainPage.aspx");
}
}