Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Passing Table Control Between Pages

$
0
0
public class PrintHelper
    {
        public PrintHelper()
        {
        }

        public static void PrintWebControl(Control ctrl, string Header, string Date)
        {
            Label lblHeader = new Label();
            lblHeader.Text = "MSJ Bank Financial - " + Header + " (" + Date + ")<br/><hr/><br/>";

            PrintWebControl(ctrl, lblHeader, string.Empty);
        }

        //Print Method
        public static void PrintWebControl(Control ctrl, Label lblHeader, string Script)
        {
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            if (ctrl is WebControl)
            {
                Unit w = new Unit(100, UnitType.Percentage);
                ((WebControl)ctrl).Width = w;
            }
            Page pg = new Page();
            pg.EnableEventValidation = false;
            if (Script != string.Empty)
            {
                pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
            }
            HtmlForm frm = new HtmlForm();
            pg.Controls.Add(frm);
            frm.Attributes.Add("runat", "server");
            frm.Controls.Add(lblHeader);
            frm.Controls.Add(ctrl);
            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();
        }
    }

From page1.aspx i have a repeater

<div id="Report" runat="server"><asp:Repeater ID="rptView" runat="server" OnItemDataBound="rptView_ItemDataBound"><HeaderTemplate><table class="table"><tr class="RepeaterHeader"><th align="center">Date</th><th align="center">Amount</th><th align="center">Description</th></tr></HeaderTemplate><ItemTemplate><tr class="RepeaterData"><td align="center"><%#Eval("Date", "{0:d}") %></td><td align="center"><%#Eval("Amount", "{0:C}")%></td><td align="center"><%#Eval("Description")%></td></tr></ItemTemplate><FooterTemplate></table></FooterTemplate></asp:Repeater><br /><br /><table><tr><td><asp:Label runat="server" Text="Grand Total Amount: " /></td><td><asp:Label ID="lblLoanAmt" runat="server" /></td></tr></table></div>

and when a print button is clicked, 

        protected void Print(object sender, EventArgs e)
        {
            string strDate = (ddlMonth.SelectedItem.Text + " / " + ddlYear.SelectedItem.Text).ToString();
            string strScript = "<script language=javascript>";
            strScript += "window.open('PrintReportTemplates.aspx','Report Print','height=2000px,width=1800px,scrollbars=1');";
            strScript += "</script>";
            Session["Control"] = Report;
            Session["Header"] = Header.Text;
            Session["Date"] = strDate;

            ClientScript.RegisterStartupScript(this.GetType(), "onclick", strScript);
            BasePage.Alert.Show("Please Print It!", ResolveClientUrl("~/Member/Home.aspx"));
        }

And it will go to PrintReportTemplates.aspx, and when the PrintReportTemplates.aspx Page_Load() will actually called the Method of PrintHelper..

Notice that my page1.aspx table design has a attribute <class="table">

But whenever i pass to PrintReportTemplates.aspx, the design is gone. How can i ensure the class="table" is passing as well??



Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>