次の方法で共有


HtmlTextWriter.RenderAfterTag メソッド

マークアップ要素の終了タグの後に出現する空白文字またはテキストを書き込みます。

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

構文

'宣言
Protected Overridable Function RenderAfterTag As String
'使用
Dim returnValue As String

returnValue = Me.RenderAfterTag
protected virtual string RenderAfterTag ()
protected:
virtual String^ RenderAfterTag ()
protected String RenderAfterTag ()
protected function RenderAfterTag () : String
適用できません。

戻り値

要素の終了タグの後に書き込む空白文字またはテキスト。

解説

RenderAfterTag メソッドは、要素タグの後に終了タグを追加して出力する場合に便利です。

継承元へのメモ : HtmlTextWriter クラスで実装されている RenderAfterTag メソッドは、null 参照 (Visual Basic では Nothing) を返します。要素の終了タグの後にテキストまたは空白文字を書き込む場合は、RenderAfterTag をオーバーライドします。

使用例

RenderAfterTag メソッドをオーバーライドして、HtmlTextWriter クラスから派生したクラスが <label> 要素を出力するかどうかを確認する方法を次のコード例に示します。出力する場合は、RenderAfterTag オーバーライドが <label> 要素の直後に、<font> 要素の終了タグを挿入します。<label> 要素でない場合は、RenderAfterTag 基本メソッドが使用されます。

    ' Override the RenderAfterTag method to add the 
    ' closing tag of the Font element after the 
    ' closing tag of a Label element has been rendered.
    Protected Overrides Function RenderAfterTag() As String
        ' Compare the TagName property value to the
        ' string label to determine whether the element to 
        ' be rendered is a Label. If it is a Label,
        ' the closing tag of a Font element is rendered
        ' after the closing tag of the Label element.
        If String.Compare(TagName, "label") = 0 Then
            Return "</font>"
            ' If a Label is not being rendered, use 
            ' the base RenderAfterTag method.
        Else
            Return MyBase.RenderAfterTag()
        End If
    End Function 'RenderAfterTag
End Class 'htwFour 
// Override the RenderAfterTag method to add the 
// closing tag of the Font element after the 
// closing tag of a Label element has been rendered.
protected override string RenderAfterTag()
{
    // Compare the TagName property value to the
    // string label to determine whether the element to 
    // be rendered is a Label. If it is a Label,
    // the closing tag of a Font element is rendered
    // after the closing tag of the Label element.
    if (String.Compare(TagName, "label") == 0)
    {
        return "</font>";
    }
    // If a Label is not being rendered, use 
        // the base RenderAfterTag method.
    else
    {
        return base.RenderAfterTag();
    }
}
// Override the RenderAfterTag method to add the
// closing tag of the Font element after the
// closing tag of a Label element has been rendered.
virtual String^ RenderAfterTag() override
{
   // Compare the TagName property value to the
   // String* label to determine whether the element to
   // be rendered is a Label. If it is a Label,
   // the closing tag of a Font element is rendered
   // after the closing tag of the Label element.
   if ( String::Compare( TagName, "label" ) == 0 )
   {
      return "</font>";
   }
   // If a Label is not being rendered, use
   // the base RenderAfterTag method.
   else
   {
      return __super::RenderAfterTag();
   }
}
// Override the RenderAfterTag method to add the 
// closing tag of the Font element after the 
// closing tag of a Label element has been rendered.
protected String RenderAfterTag()
{
    // Compare the TagName property value to the
    // string label to determine whether the element to 
    // be rendered is a Label. If it is a Label,
    // the closing tag of a Font element is rendered
    // after the closing tag of the Label element.
    if (String.Compare(get_TagName(), "label") == 0) {
        return "</font>";
    }
        // If a Label is not being rendered, use 
        // the base RenderAfterTag method.
    else {
        return super.RenderAfterTag();
    }
} //RenderAfterTag

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HtmlTextWriter クラス
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter