Thursday, May 17, 2012

c# .net web application add server control into literal using stringbuilder

StringBuilder sb = new StringBuilder();
TextBox TextBox1 = new TextBox ();
TextBox1.ID = "TextBox1";
TextBox1.Text = "Hello World";
using (StringWriter sw = new StringWriter(sb))
{
using (HtmlTextWriter tw = new HtmlTextWriter(sw))
{
TextBox1.RenderControl(tw);
}
}

No comments: