Monday, August 10, 2009

Getting HTML from ascx and place the html in another aspx page

//namespace
using System.Text;
using System.IO;

Control c = Page.LoadControl("WebUserControl.ascx");
((UserControlBaseSoloDesign)c).function(string username)//function in webusercontrol.ascx for displaying in ascx page
form1.Controls.Add(c); //form 1 is the control in the page
StringWriter sw = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sw);
string contents = null;
try
{
c.RenderControl(writer);
contents = sw.GetStringBuilder().ToString();
}
finally
{
sw.Close();
writer.Close();
}
Response.Write(contents.ToString());

No comments:

Post a Comment