ASP.NET: Getting markup for .ascx
问题 Let's say I have an a .ascx user control. How do I get its HTML markup into a string? 回答1: Once you use the LoadControl() method to get it into a page, you can can get the HTML by calling the Render() method on it. It requires an HtmlTextWriter to write to, but it's fairly straightforward to construct: var userControl = (userControlType)Page.LoadControl( ....ascx); StringBuilder sb = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htw = new HtmlTextWriter(new