Thursday, February 21, 2008

Load WebUserControl programmatically and Print it using session

Control _myControl;
protected void Page_Load(object sender, EventArgs e)
{
_myControl = LoadControl("SubContent1.ascx");
Arlyia_SubContent1 _subContent = (Arlyia_SubContent1)_myControl;
_subContent.XmlDataSourceXPath = "contents/content[@name='MainContent1']/subcontent[@name='SubContent1']/htmlcode[@language='"+Session["language"].ToString()+"']";
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(_myControl);
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Session["ControlsToPrint"] = _myControl;
//Response.Write("var printWindow = window.open('PrintWindow.aspx', 'PrintWindow'," + "'toolbars=no,status=no,width=300,top=10,left=10,height=300,resizable=no,scrollbars=no,menubar=no');");

//Control _myPrintingPageControl = LoadControl("~/PrintingPage/PrintingPageControl.ascx");
//PrintingPage_PrintingPageControl _printingPage = (PrintingPage_PrintingPageControl)_myPrintingPageControl;

//_printingPage.MyControl = _myControl;

//_printingPage.Page.RegisterClientScriptBlock("", "");

//PlaceHolder2.Controls.Add(_myPrintingPageControl);

//TextBox a = (TextBox)_printingPage.FindControl("TextBox1");
//a.Text = "shit";

Page.RegisterClientScriptBlock("", "");

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb = PlaceHolder1;

//Response.Write(bb.Controls[0].ToString());

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb.Controls.Add(a);
//Response.Redirect("~/PrintingPage/PrintingPage.aspx");
//_myControl.PlaceHoder.Controls.Add(a);
}

No comments: