HtmlTextWriter クラスとは? わかりやすく解説

HtmlTextWriter クラス

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class HtmlTextWriter
    Inherits TextWriter
Dim instance As HtmlTextWriter
public class HtmlTextWriter : TextWriter
public ref class HtmlTextWriter : public
 TextWriter
public class HtmlTextWriter extends TextWriter
public class HtmlTextWriter extends
 TextWriter
解説解説
使用例使用例

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 &quot;encoding &quot; 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 &quot;encoding &quot; 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.Object
   System.MarshalByRefObject
     System.IO.TextWriter
      System.Web.UI.HtmlTextWriter
         System.Web.UI.Html32TextWriter
         System.Web.UI.MobileControls.Adapters.MultiPartWriter
         System.Web.UI.XhtmlTextWriter
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter
Control クラス
Page
ControlAdapter
PageAdapter
ChtmlTextWriter クラス
Html32TextWriter クラス
XhtmlTextWriter
Control.Render


このページでは「.NET Framework クラス ライブラリ リファレンス」からHtmlTextWriter クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHtmlTextWriter クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHtmlTextWriter クラスを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HtmlTextWriter クラス」の関連用語

HtmlTextWriter クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlTextWriter クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS