Getting the raw HTML from a web control

Ever need the raw HTML produced by a .NET server control?  It's easy with .NET!
Option Strict On
Option Explicit On

Imports System
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

Public Class App1 
    Shared Sub Main()
        Dim ctl As TextBox = New TextBox()
        ctl.BackColor = Color.Red
        ctl.Height = New Unit(200)
        Dim sw As StringWriter = New StringWriter()
        ctl.RenderControl(New HtmlTextWriter(sw))
        Console.WriteLine(sw.ToString())
    End Sub
End Class

When run, you should get the following output in the console window:

<INPUT style="HEIGHT: 200px; BACKGROUND-COLOR: red">

1 Comment

  • Hi

    That is nice!

    Do you know a way to get my page's whole output html that will be sent to the client? I want to filter it or add sth to it

    Thanks

    Behdad

Comments have been disabled for this content.