Page.CreateHtmlTextWriter Method
.NET Framework 3.0
Creates an HtmlTextWriter object to render the page's content.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
protected HtmlTextWriter CreateHtmlTextWriter ( TextWriter tw )
protected internal function CreateHtmlTextWriter ( tw : TextWriter ) : HtmlTextWriter
Not applicable.
Parameters
- tw
The TextWriter used to create the HtmlTextWriter.
Return Value
An HtmlTextWriter or Html32TextWriter.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.
import System.*;
import System.IO.*;
import System.Web.UI.*;
public class MyPage extends Page
{
public MyPage()
{
} //MyPage
protected HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new MyHtmlTextWriter(writer);
} //CreateHtmlTextWriter
protected void Render(HtmlTextWriter writer)
{
// Write 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.get_Now().ToLongTimeString());
writer.RenderEndTag();
} //Render
} //MyPage
public class MyHtmlTextWriter extends HtmlTextWriter
{
public MyHtmlTextWriter(TextWriter writer)
{
super(writer);
writer.Write("<font color=blue> 'MyHtmlTextWriter' is used for "
+ "rendering.</font>");
} //MyHtmlTextWriter
} //MyHtmlTextWriter
Community Additions
ADD
Show: