- Imports System.Text
- Imports System.IO
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


