Tuesday 25 December 2012

Convert Html control to string

eg: In server side, through coding, we have created a HTMLAnchor. Adding this to a Label's text requires in string format.
 
private static string GetControlsAsString(Control ulControl)
{
 string contents = null;
 using (System.IO.StringWriter swriter = new System.IO.StringWriter())
 {
 HtmlTextWriter writer = new HtmlTextWriter(swriter);
 ulControl.RenderControl(writer);
 contents = swriter.ToString();
 }
 return contents;
}

No comments:

Post a Comment