ChtmlTextWriter Costruttori

Definizione

Inizializza una nuova istanza della classe ChtmlTextWriter.

Overload

ChtmlTextWriter(TextWriter)

Inizializza una nuova istanza della classe ChtmlTextWriter che utilizza la costante DefaultTabString per applicare il rientro alle righe.

ChtmlTextWriter(TextWriter, String)

Inizializza una nuova istanza della classe ChtmlTextWriter con il rientro della riga specificato.

ChtmlTextWriter(TextWriter)

Inizializza una nuova istanza della classe ChtmlTextWriter che utilizza la costante DefaultTabString per applicare il rientro alle righe.

public:
 ChtmlTextWriter(System::IO::TextWriter ^ writer);
public ChtmlTextWriter (System.IO.TextWriter writer);
new System.Web.UI.ChtmlTextWriter : System.IO.TextWriter -> System.Web.UI.ChtmlTextWriter
Public Sub New (writer As TextWriter)

Parametri

writer
TextWriter

Oggetto TextWriter che esegue il rendering del contenuto del markup.

Esempio

Nell'esempio di codice seguente viene illustrato come creare una classe denominata ChtmlCustomPageAdapter e definire un metodo, CreateCustomChtmlTextWriter, che crea e restituisce un'istanza della CustomChtmlTextWriter classe . Esegue CustomChtmlTextWriter quindi il rendering del contenuto cHTML per le pagine nei dispositivi con browser che usano markup cHTML.

Questo esempio di codice fa parte di un esempio più ampio fornito per la ChtmlTextWriter classe .

// 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);
    }
}
' Derive from the WebControlAdapter class,
' provide a CreateCustomChtmlTextWriter
' method to attach the custom writer.
Public Class ChtmlCustomPageAdapter
    Inherits WebControlAdapter

    Protected Friend Function CreateCustomChtmlTextWriter( _
     ByVal writer As TextWriter) As ChtmlTextWriter

        Return New CustomChtmlTextWriter(writer)

    End Function
End Class

Commenti

La ChtmlTextWriter classe ha due costruttori, ovvero standard per tutte le classi che derivano direttamente o indirettamente dalla HtmlTextWriter classe .

Il ChtmlTextWriter costruttore, che accetta un'istanza della TextWriter classe come parametro, chiama il secondo costruttore e lo passa due valori di parametro:

  • Oggetto TextWriter.

  • Valore stringa specificato nel DefaultTabString campo , che definisce la spaziatura di tabulazione utilizzata dal writer di testo XHTML.

Si applica a

ChtmlTextWriter(TextWriter, String)

Inizializza una nuova istanza della classe ChtmlTextWriter con il rientro della riga specificato.

public:
 ChtmlTextWriter(System::IO::TextWriter ^ writer, System::String ^ tabString);
public ChtmlTextWriter (System.IO.TextWriter writer, string tabString);
new System.Web.UI.ChtmlTextWriter : System.IO.TextWriter * string -> System.Web.UI.ChtmlTextWriter
Public Sub New (writer As TextWriter, tabString As String)

Parametri

writer
TextWriter

Oggetto TextWriter che esegue il rendering del contenuto del markup.

tabString
String

Numero di spazi definiti nella proprietà Indent.

Esempio

Nell'esempio di codice seguente viene illustrato come creare una classe personalizzata denominata CustomChtmlTextWriter derivata dalla ChtmlTextWriter classe . Crea due costruttori che è possibile usare per creare un'istanza della classe personalizzata con lo stesso modello di tutte le classi che derivano, direttamente o indirettamente, dalla HtmlTextWriter classe .

// 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);
        }
    }
}
' Create a class that derives from the
' ChtmlTextWriter class.
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls.Adapters

Namespace AspNet.Samples.VB

    Public Class CustomChtmlTextWriter
        Inherits ChtmlTextWriter

        ' Create two constructors for the new
        ' text writer.
        Public Sub New(ByVal writer As TextWriter)
            MyClass.New(writer, DefaultTabString)
        End Sub

        Public Sub New(ByVal writer As TextWriter, ByVal tabString As String)
            MyBase.New(writer, tabString)
        End Sub

        ' Override the OnAttributeRender method to
        ' not render the bgcolor attribute, which is 
        ' not supported in CHTML.
        Protected Overrides Function OnAttributeRender(ByVal name As String, ByVal value As String, ByVal key As HtmlTextWriterAttribute) As Boolean
            If (String.Equals("bgcolor", name)) Then
                Return False
            End If

            ' Call the ChtmlTextWriter version of 
            ' the OnAttributeRender method.
            MyBase.OnAttributeRender(name, value, key)

        End Function
    End Class

    ' Derive from the WebControlAdapter class,
    ' provide a CreateCustomChtmlTextWriter
    ' method to attach the custom writer.
    Public Class ChtmlCustomPageAdapter
        Inherits WebControlAdapter

        Protected Friend Function CreateCustomChtmlTextWriter( _
         ByVal writer As TextWriter) As ChtmlTextWriter

            Return New CustomChtmlTextWriter(writer)

        End Function
    End Class
End Namespace

Commenti

Il ChtmlTextWriter costruttore, che accetta sia un'istanza della TextWriter classe che una stringa come parametri, chiama il Html32TextWriter costruttore che accetta gli stessi parametri quando crea un'istanza della ChtmlTextWriter classe .

Si applica a