<p>I have any ASP.NET control.  I want the HTML string how to do I get the HTML string of the control?</p>

[{'answer_id': 58931, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 6, 'selected': True, 'text': '<p>This appears to work.</p>\n\n<pre><code>public string RenderControlToHtml(Control ControlToRender)\n{\n    System.Text.StringBuilder sb = new System.Text.StringBuilder();\n    System.IO.StringWriter stWriter = new System.IO.StringWriter(sb);\n    System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(stWriter);\n    ControlToRender.RenderControl(htmlWriter);\n    return sb.ToString();\n}\n</code></pre>\n'}, {'answer_id': 59323, 'author': 'a7drew', 'author_id': 4239, 'author_profile': 'https://Stackoverflow.com/users/4239', 'pm_score': 3, 'selected': False, 'text': '<p>If your control is a web user control, this is how you can get to the HTML it emits from another page or handler:</p>\n\n<pre><code>public void GetHtmlFromMySweetControl(HttpContext context)\n{\n    HttpRequest httpRequest = context.Request;\n    HttpResponse httpResponse = context.Response;\n\n    string foo = httpRequest["foo"];\n\n    Page pageHolder = new Page();\n    string path = "~/usercontrols/MySweetControl.ascx";\n    MySweetControl ctrl = (MySweetControl)pageHolder.LoadControl(path);\n    ctrl.BindProducts(foo);\n    pageHolder.Controls.Add(ctrl);\n\n    StringWriter sw = new StringWriter();\n    context.Server.Execute(pageHolder, sw, false);\n    httpResponse.Write(sw.ToString());\n}\n</code></pre>\n'}, {'answer_id': 32765865, 'author': 'avs099', 'author_id': 1246870, 'author_profile': 'https://Stackoverflow.com/users/1246870', 'pm_score': 4, 'selected': False, 'text': '<p>Accepted answer by <code>David Basarab</code> will not work if control is not part of the page. <code>a7drew</code>\'s answer seems unnecessary complex - no need in <code>Context</code> or <code>Server.Execute</code>.</p>\n\n<pre><code>private string RenderControl()\n{\n    var sb = new System.Text.StringBuilder();\n    using (var stWriter = new System.IO.StringWriter(sb))\n    using (var htmlWriter = new HtmlTextWriter(stWriter))\n    {\n        var p = new Page();\n        var ctrl = (YourControl)p.LoadControl("~/controls/building blocks/YourControl.ascx");\n        ctrl.Visible = true;\n\n        // do your own init logic if needed\n\n        p.Controls.Add(ctrl);\n        ctrl.RenderControl(htmlWriter);\n        return sb.ToString();\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/58925', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2469/']