Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

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: 1.8/5 (4 votes cast)