Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

ASP.NET: Render a control to a string

From Wiki

Jump to: navigation, search

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:

  1. Public Function RenderControlToString(ByVal ctrl As Control) As String
  2.     Dim sb As StringBuilder = New StringBuilder
  3.     Dim tw As StringWriter = New StringWriter(sb)
  4.     Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
  5.     ctrl.RenderControl(hw)
  6.     Return sb.ToString
  7. End Function

You may also need to add these Imports statements:

  1. Imports System.Text
  2. Imports System.IO


This Hack is part of the ASP.NET Hacks collection

485 Rating: 0.0/5 (0 votes cast)