ChtmlTextWriter Constructor (TextWriter, String)
Initializes a new instance of the ChtmlTextWriter class with the specified line indentation.
Assembly: System.Web (in System.Web.dll)
Parameters
- writer
-
Type:
System.IO.TextWriter
The TextWriter that renders the markup content.
- tabString
-
Type:
System.String
The number of spaces defined in the Indent.
The ChtmlTextWriter constructor, which takes both an instance of the TextWriter class and a string as parameters, calls the Html32TextWriter constructor that takes the same parameters when it creates an instance of the ChtmlTextWriter class.
The following code example demonstrates how to create a custom class named CustomChtmlTextWriter that is derived from the ChtmlTextWriter class. It creates two constructors that you can use to create an instance of the custom class with the same pattern as all classes that derive, directly or indirectly, from the HtmlTextWriter class.
// Create a class that derives from the // ChtmlTextWriter class. using System; using System.IO; using System.Web.UI; using System.Web.UI.WebControls.Adapters; namespace AspNet.Samples.CS { public class CustomChtmlTextWriter : ChtmlTextWriter { // Create two constructors for the new // text writer. public CustomChtmlTextWriter(TextWriter writer) : base(writer, DefaultTabString) { } public CustomChtmlTextWriter(TextWriter writer, String tabString) : base(writer, tabString) { } // Override the OnAttributeRender method to // not render the bgcolor attribute, which is // not supported in CHTML. protected override bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key) { if (String.Equals("bgcolor", name)) { return false; } // Call the ChtmlTextWriter version of the // the OnAttributeRender method. return base.OnAttributeRender(name, value, key); } } // Derive from the WebControlAdapter class, // provide a CreateCustomChtmlTextWriter // method to attach to the custom writer. public class ChtmlCustomPageAdapter : WebControlAdapter { protected internal ChtmlTextWriter CreateCustomChtmlTextWriter( TextWriter writer) { return new CustomChtmlTextWriter(writer); } } }
Available since 2.0