HtmlTextWriter クラス
アセンブリ: System.Web (system.web.dll 内)

Public Class HtmlTextWriter Inherits TextWriter
public class HtmlTextWriter : TextWriter
public class HtmlTextWriter extends TextWriter
public class HtmlTextWriter extends TextWriter

HtmlTextWriter クラスは、HTML 4.0 をデスクトップ ブラウザに表示するために使用します。HtmlTextWriter は、ChtmlTextWriter クラス、Html32TextWriter クラス、XhtmlTextWriter クラスなどの System.Web.UI 名前空間のすべてのマークアップ ライタの基本クラスでもあります。これらのクラスは、さまざまな種類のマークアップの要素、属性、スタイル、およびレイアウト情報を書き込むために使用されます。さらに、これらのクラスは、各マークアップ言語に関連付けられたページとコントロール アダプタ クラスで使用されます。
ほとんどの場合、ASP.NET は、要求側のデバイスに適したライタを自動的に使用します。ただし、カスタム テキスト ライタを作成したり、特定のライタを指定して特定のデバイスにページを出力したりする場合は、アプリケーションの .browser ファイルの controlAdapters セクションで、ページにライタを割り当てる必要があります。

Control クラスから派生したカスタム コントロールの Render メソッドをオーバーライドする方法を次のコード例に示します。このコード例では、HtmlTextWriter のさまざまなメソッド、プロパティ、およびフィールドの使用方法を示しています。
' Overrides the Render method to write a <span> element ' that applies styles and attributes. Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) ' Set attributes and values along with attributes and styles ' attribute defined for a <span> element. writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');") writer.AddAttribute("CustomAttribute", "CustomAttributeValue") writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red") writer.AddStyleAttribute("CustomStyle", "CustomStyleValue") writer.RenderBeginTag(HtmlTextWriterTag.Span) ' Create a space and indent the markup inside the ' <span> element. writer.WriteLine() writer.Indent += 1 writer.Write("Hello") writer.WriteLine() ' Controls the encoding of markup attributes ' for an <img> element. Simple known values ' do not need encoding. writer.AddAttribute(HtmlTextWriterAttribute.Alt, _ "Encoding, ""Required""", _ True) writer.AddAttribute("myattribute", _ "No "encoding " required", _ False) writer.RenderBeginTag(HtmlTextWriterTag.Img) writer.RenderEndTag() writer.WriteLine() ' Create a non-standard markup element. writer.RenderBeginTag("Mytag") writer.Write("Contents of MyTag") writer.RenderEndTag() writer.WriteLine() ' Create a manually rendered <img> element ' that contains an alt attribute. writer.WriteBeginTag("img") writer.WriteAttribute("alt", "A custom image.") writer.Write(HtmlTextWriter.TagRightChar) writer.WriteEndTag("img") writer.WriteLine() writer.Indent -= 1 writer.RenderEndTag() End Sub 'Render
// Overrides the Render method to write a <span> element // that applies styles and attributes. protected override void Render(HtmlTextWriter writer) { // Set attributes and values along with attributes and styles // attribute defined for a <span> element. writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');"); writer.AddAttribute("CustomAttribute", "CustomAttributeValue"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red"); writer.AddStyleAttribute("Customstyle", "CustomStyleValue"); writer.RenderBeginTag(HtmlTextWriterTag.Span); // Create a space and indent the markup inside the // <span> element. writer.WriteLine(); writer.Indent++; writer.Write("Hello"); writer.WriteLine(); // Controls the encoding of markup attributes // for an <img> element. Simple known values // do not need encoding. writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, \"Required\"", true); writer.AddAttribute("myattribute", "No "encoding " required", false); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); writer.WriteLine(); // Create a non-standard markup element. writer.RenderBeginTag("MyTag"); writer.Write("Contents of MyTag"); writer.RenderEndTag(); writer.WriteLine(); // Create a manually rendered <img> element // that contains an alt attribute. writer.WriteBeginTag("img"); writer.WriteAttribute("alt", "A custom image."); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("img"); writer.WriteLine(); writer.Indent--; writer.RenderEndTag(); }

System.MarshalByRefObject
System.IO.TextWriter
System.Web.UI.HtmlTextWriter
System.Web.UI.Html32TextWriter
System.Web.UI.MobileControls.Adapters.MultiPartWriter
System.Web.UI.XhtmlTextWriter


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTextWriter コンストラクタ (TextWriter)
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ writer As TextWriter _ )
public HtmlTextWriter ( TextWriter writer )
public: HtmlTextWriter ( TextWriter^ writer )
public HtmlTextWriter ( TextWriter writer )
public function HtmlTextWriter ( writer : TextWriter )

HtmlTextWriter(TextWriter) コンストラクタの HtmlTextWriter オーバーロードは、行のインデントが必要な場合に DefaultTabString 定数を使用します。これにより、HtmlTextWriter(TextWriter,String) オーバーロードが呼び出され、新しいインスタンスが初期化されます。

HtmlTextWriter(TextWriter) コンストラクタを使用して、StyledLabelHtmlWriter という名前のカスタム HtmlTextWriter オブジェクトを作成する方法を次のコード例に示します。Page クラスから派生した MyPage カスタム クラスがクライアント ブラウザによって要求されると、StyledLabelHtmlWriter クラスを使用して、出力ストリームに内容が出力されます。
' 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 'MyPage
// 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 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. public class MyPage extends Page { protected HtmlTextWriter CreateHtmlTextWriter(TextWriter writer) { return new HtmlStyledLabelWriter(writer); } //CreateHtmlTextWriter } //MyPage

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTextWriter コンストラクタ

名前 | 説明 |
---|---|
HtmlTextWriter (TextWriter) | 既定のタブ文字列を使用する HtmlTextWriter クラスの新しいインスタンスを初期化します。 |
HtmlTextWriter (TextWriter, String) | タブ文字列を指定して、HtmlTextWriter クラスの新しいインスタンスを初期化します。 |

HtmlTextWriter コンストラクタ (TextWriter, String)
アセンブリ: System.Web (system.web.dll 内)

Dim writer As TextWriter Dim tabString As String Dim instance As New HtmlTextWriter(writer, tabString)
public HtmlTextWriter ( TextWriter writer, string tabString )
public: HtmlTextWriter ( TextWriter^ writer, String^ tabString )
public HtmlTextWriter ( TextWriter writer, String tabString )

HtmlTextWriter(TextWriter,String) コンストラクタの HtmlTextWriter オーバーロードは、行のインデントが必要な場合に tabString を使用します。これにより、System.IO.TextWriter 基本コンストラクタが呼び出され、新しいインスタンスが初期化されます。

HtmlTextWriter(TextWriter) コンストラクタを使用して、StyledLabelHtmlWriter という名前のカスタム HtmlTextWriter オブジェクトを作成する方法を次のコード例に示します。Page クラスから派生した MyPage カスタム クラスがクライアント ブラウザによって要求されると、StyledLabelHtmlWriter クラスを使用して、出力ストリームに内容が出力されます。
' 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 'MyPage
// 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 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. public class MyPage extends Page { protected HtmlTextWriter CreateHtmlTextWriter(TextWriter writer) { return new HtmlStyledLabelWriter(writer); } //CreateHtmlTextWriter } //MyPage

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTextWriter フィールド

名前 | 説明 | |
---|---|---|
![]() | DefaultTabString | 単一のタブ文字を表します。 |
![]() | DoubleQuoteChar | 引用符 (") を表します。 |
![]() | EndTagLeftChars | マークアップ要素の終了タグの左山かっことスラッシュ記号 (</) を表します。 |
![]() | EqualsChar | 等号記号 (=) を表します。 |
![]() | EqualsDoubleQuoteString | 文字列 (=") の等号 (=) と二重引用符文字 (") の両方を表します。 |
![]() | SelfClosingChars | マークアップ タグの空白文字と自己終了スラッシュ記号 (/) を表します。 |
![]() | SelfClosingTagEnd | 自己終了マークアップ要素の終了スラッシュ記号と右山かっこ (/>) を表します。 |
![]() | SemicolonChar | セミコロン (;) を表します。 |
![]() | SingleQuoteChar | アポストロフィ (') を表します。 |
![]() | SlashChar | スラッシュ記号 (</) を表します。 |
![]() | SpaceChar | 空白文字 ( ) を表します。 |
![]() | StyleEqualsChar | スタイル属性を値に等しく設定するために使用するスタイル イコール (:) 文字を表します。 |
![]() | TagLeftChar | マークアップ タグの左山かっこ (<) を表します。 |
![]() | TagRightChar | マークアップ タグの右山かっこ (>) を表します。 |

名前 | 説明 | |
---|---|---|
![]() | CoreNewLine | TextWriter で使用する改行文字を格納します。 ( TextWriter から継承されます。) |

HtmlTextWriter プロパティ

名前 | 説明 | |
---|---|---|
![]() | Encoding | オーバーライドされます。 HtmlTextWriter オブジェクトがページに内容を書き込むために使用するエンコーディングを取得します。 |
![]() | FormatProvider | 書式を制御するオブジェクトを取得します。 ( TextWriter から継承されます。) |
![]() | Indent | マークアップの各行の開始位置のインデントを設定するタブ位置の数を取得または設定します。 |
![]() | InnerWriter | マークアップ要素の内部の内容を書き込むテキスト ライタを取得または設定します。 |
![]() | NewLine | オーバーライドされます。 HtmlTextWriter オブジェクトで使用される行終端文字列を取得または設定します。 |


HtmlTextWriter メソッド



HtmlTextWriter メンバ
マークアップ文字とテキストを ASP.NET サーバー コントロールの出力ストリームに書き込みます。このクラスには、ASP.NET サーバー コントロールがマークアップをクライアントに表示するときに使用する書式設定機能が用意されています。
HtmlTextWriter データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | DefaultTabString | 単一のタブ文字を表します。 |
![]() | DoubleQuoteChar | 引用符 (") を表します。 |
![]() | EndTagLeftChars | マークアップ要素の終了タグの左山かっことスラッシュ記号 (</) を表します。 |
![]() | EqualsChar | 等号記号 (=) を表します。 |
![]() | EqualsDoubleQuoteString | 文字列 (=") の等号 (=) と二重引用符文字 (") の両方を表します。 |
![]() | SelfClosingChars | マークアップ タグの空白文字と自己終了スラッシュ記号 (/) を表します。 |
![]() | SelfClosingTagEnd | 自己終了マークアップ要素の終了スラッシュ記号と右山かっこ (/>) を表します。 |
![]() | SemicolonChar | セミコロン (;) を表します。 |
![]() | SingleQuoteChar | アポストロフィ (') を表します。 |
![]() | SlashChar | スラッシュ記号 (</) を表します。 |
![]() | SpaceChar | 空白文字 ( ) を表します。 |
![]() | StyleEqualsChar | スタイル属性を値に等しく設定するために使用するスタイル イコール (:) 文字を表します。 |
![]() | TagLeftChar | マークアップ タグの左山かっこ (<) を表します。 |
![]() | TagRightChar | マークアップ タグの右山かっこ (>) を表します。 |

名前 | 説明 | |
---|---|---|
![]() | CoreNewLine | TextWriter で使用する改行文字を格納します。(TextWriter から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Encoding | オーバーライドされます。 HtmlTextWriter オブジェクトがページに内容を書き込むために使用するエンコーディングを取得します。 |
![]() | FormatProvider | 書式を制御するオブジェクトを取得します。(TextWriter から継承されます。) |
![]() | Indent | マークアップの各行の開始位置のインデントを設定するタブ位置の数を取得または設定します。 |
![]() | InnerWriter | マークアップ要素の内部の内容を書き込むテキスト ライタを取得または設定します。 |
![]() | NewLine | オーバーライドされます。 HtmlTextWriter オブジェクトで使用される行終端文字列を取得または設定します。 |




Weblioに収録されているすべての辞書からHtmlTextWriterを検索する場合は、下記のリンクをクリックしてください。

- HtmlTextWriterのページへのリンク