マークアップ要素の開始タグの前に出現するテキストまたは空白文字を書き込みます。
名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Overridable Function RenderBeforeTag As String
'使用
Dim returnValue As String
returnValue = Me.RenderBeforeTag
protected virtual string RenderBeforeTag ()
protected:
virtual String^ RenderBeforeTag ()
protected String RenderBeforeTag ()
protected function RenderBeforeTag () : String
適用できません。
戻り値
マークアップ要素の開始タグの前に書き込むテキストまたは空白文字。オーバーライドされない場合は null 参照 (Visual Basic では Nothing)。
解説
RenderBeforeTag メソッドは、対象とする要素の開始タグの前に開始タグを追加して出力する場合に便利です。
実装元へのメモ : HtmlTextWriter クラスで実装されている RenderBeforeTag メソッドは、null 参照 (Visual Basic では Nothing) を返します。要素の開始タグの前にテキストまたは空白文字を書き込む場合は、RenderBeforeTag をオーバーライドします。
使用例
RenderBeforeTag メソッドをオーバーライドして、HtmlTextWriter クラスから派生したクラスが <label> 要素を出力するかどうかを確認する方法を次のコード例に示します。出力する場合は、RenderBeforeTag オーバーライドが <label> 要素の直前に、<font> 要素の開始タグを挿入します。<label> 要素を出力しない場合は、RenderBeforeTag 基本メソッドが使用されます。
' Override the RenderBeforeTag method to add the
' opening tag of a Font element before the
' opening tag of any Label elements rendered by this
' custom markup writer.
Protected Overrides Function RenderBeforeTag() 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 opening tag of the Font element, with a Color
' style attribute set to red, is added before
' the Label.
If String.Compare(TagName, "label") = 0 Then
Return "<font color=""red"">"
' If a Label is not being rendered, use
' the base RenderBeforeTag method.
Else
Return MyBase.RenderBeforeTag()
End If
End Function 'RenderBeforeTag
// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom markup writer.
protected override string RenderBeforeTag()
{
// 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 opening tag of the Font element, with a Color
// style attribute set to red, is added before
// the Label.
if (String.Compare(TagName, "label") == 0)
{
return "<font color=\"red\">";
}
// If a Label is not being rendered, use
// the base RenderBeforeTag method.
else
{
return base.RenderBeforeTag();
}
}
// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom markup writer.
virtual String^ RenderBeforeTag() 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 opening tag of the Font element, with a Color
// style attribute set to red, is added before
// the Label.
if ( String::Compare( TagName, "label" ) == 0 )
{
return "<font color=\"red\">";
}
// If a Label is not being rendered, use
// the base RenderBeforeTag method.
else
{
return __super::RenderBeforeTag();
}
}
// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom markup writer.
protected String RenderBeforeTag()
{
// 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 opening tag of the Font element, with a Color
// style attribute set to red, is added before
// the Label.
if (String.Compare(get_TagName(), "label") == 0) {
return "<font color=\"red\">";
}
// If a Label is not being rendered, use
// the base RenderBeforeTag method.
else {
return super.RenderBeforeTag();
}
} //RenderBeforeTag
プラットフォーム
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