using System.Text;
using System.IO;
using System.Web.UI;
Below is RenderControl method implementation, which receives any control and returns its HTML string representation.
public string RenderControl(Control ctrl)
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctrl.RenderControl(hw);
return sb.ToString();
}