- Imports System.Text
- Imports System.IO
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Render a control to a string
From Wiki
Summary: Render a control to a string
Getting the rendered contents of a control can be very useful in situation where you may want to email or send the details out to an external source.
To get the contents is actually quite simple and can be seen in this example:
- Public Function RenderControlToString(ByVal ctrl As Control) As String
- Dim sb As StringBuilder = New StringBuilder
- Dim tw As StringWriter = New StringWriter(sb)
- Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
- ctrl.RenderControl(hw)
- Return sb.ToString
- End Function
You may also need to add these Imports statements:
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.