Bagikan melalui


HtmlTextWriter Konstruktor

Definisi

Menginisialisasi instans baru kelas HtmlTextWriter.

Overload

HtmlTextWriter(TextWriter)

Menginisialisasi instans HtmlTextWriter baru kelas yang menggunakan string tab default.

HtmlTextWriter(TextWriter, String)

Menginisialisasi instans HtmlTextWriter baru kelas dengan karakter string tab tertentu.

HtmlTextWriter(TextWriter)

Menginisialisasi instans HtmlTextWriter baru kelas yang menggunakan string tab default.

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

Parameter

writer
TextWriter

TextWriter Instans yang merender konten markup.

Contoh

Contoh kode berikut menunjukkan cara menggunakan HtmlTextWriter(TextWriter) konstruktor untuk membuat objek kustom HtmlTextWriter bernama StyledLabelHtmlWriter. MyPage Ketika kelas kustom, yang berasal dari Page kelas , diminta oleh browser klien, ia menggunakan StyledLabelHtmlWriter kelas untuk merender kontennya ke aliran output.

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
   virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
   {
      return gcnew HtmlStyledLabelWriter( writer );
   }
};

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
    protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
    {
        return new HtmlStyledLabelWriter(writer);
    }
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.  
<AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
    Inherits Page

    Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
        Return New HtmlStyledLabelWriter(writer)
    End Function 'CreateHtmlTextWriter
End Class

Keterangan

Kelebihan HtmlTextWriter beban HtmlTextWriter(TextWriter) konstruktor menggunakan konstanta DefaultTabString ketika indentasi garis diperlukan. Ini memanggil kelebihan beban untuk menginisialisasi instans HtmlTextWriter(TextWriter, String) baru.

Lihat juga

Berlaku untuk

HtmlTextWriter(TextWriter, String)

Menginisialisasi instans HtmlTextWriter baru kelas dengan karakter string tab tertentu.

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

Parameter

writer
TextWriter

TextWriter yang merender konten markup.

tabString
String

String yang digunakan untuk merender indentasi baris.

Contoh

Contoh kode berikut menunjukkan cara menggunakan HtmlTextWriter(TextWriter) konstruktor untuk membuat objek kustom HtmlTextWriter bernama StyledLabelHtmlWriter. MyPage Ketika kelas kustom, yang berasal dari Page kelas , diminta oleh browser klien, ia menggunakan StyledLabelHtmlWriter kelas untuk merender kontennya ke aliran output.

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
   virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
   {
      return gcnew HtmlStyledLabelWriter( writer );
   }
};

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
    protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
    {
        return new HtmlStyledLabelWriter(writer);
    }
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.  
<AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
    Inherits Page

    Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
        Return New HtmlStyledLabelWriter(writer)
    End Function 'CreateHtmlTextWriter
End Class

Keterangan

Kelebihan HtmlTextWriter beban HtmlTextWriter(TextWriter, String) konstruktor menggunakan tabString ketika indentasi garis diperlukan. Ini memanggil TextWriter.TextWriter(IFormatProvider) konstruktor dasar untuk menginisialisasi instans baru.

Lihat juga

Berlaku untuk