Page.CreateHtmlTextWriter Method
Creates an HtmlTextWriter object to render the page's content.
Assembly: System.Web (in System.Web.dll)
'Declaration Protected Friend Overridable Function CreateHtmlTextWriter ( _ tw As TextWriter _ ) As HtmlTextWriter
Parameters
- tw
- Type: System.IO.TextWriter
The TextWriter used to create the HtmlTextWriter.
The CreateHtmlTextWriter method creates a TextWriter through the Browser property of the Request object associated with the page request. You can add a reference to an HtmlTextWriter in the browserCaps configuration section. Override the CreateHtmlTextWriter method to perform custom lookup.
The following code example uses the CreateHtmlTextWriter method to create an instance of a custom HtmlTextWriter object named MyHtmlTextWriter. The CreateHtmlTextWriter method is overridden in the MyPage class, which is derived from Page, so that MyHtmlTextWriter renders ASP.NET server controls when the page is requested. Note that this example will prevent adapter TextWriter behavior.
Imports System Imports System.IO Imports System.Web.UI Namespace WebPage Public Class MyPage Inherits Page Public Sub New() MyBase.New() End Sub 'New <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter Return New MyHtmlTextWriter(writer) End Function 'CreateHtmlTextWriter <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) ' Writes a Font control. writer.AddAttribute("color", "red") writer.AddAttribute("size", "6pt") writer.RenderBeginTag(HtmlTextWriterTag.Font) writer.Write(("<br>" + "The time on the server:<br> " + System.DateTime.Now.ToLongTimeString())) writer.RenderEndTag() End Sub 'Render End Class 'MyPage Public Class MyHtmlTextWriter Inherits HtmlTextWriter Public Sub New(writer As TextWriter) MyBase.New(writer) writer.Write("<font color=blue> 'MyHtmlTextWriter' is used for rendering.</font>") End Sub 'New End Class 'MyHtmlTextWriter End Namespace 'WebPage
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.