指定した HTML 要素の HtmlTextWriterTag 値を取得または設定します。
Protected Property TagKey As HtmlTextWriterTag
[C#]
protected HtmlTextWriterTag TagKey {get; set;}
[C++]
protected: __property HtmlTextWriterTag get_TagKey();protected: __property void set_TagKey(HtmlTextWriterTag);
[JScript]
protected function get TagKey() : HtmlTextWriterTag;protected function set TagKey(HtmlTextWriterTag);
プロパティ値
開始タグが表示される HTML 要素。
例外
例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | プロパティ値が設定できません。 |
解説
このプロパティは、 HtmlTextWriter を継承するクラスにだけ使用されます。 RenderBeginTag メソッドを呼び出す場合だけ、このプロパティを読み取る、または設定します。このプロパティに一定の値を設定するのはこの場合に限られます。
使用例
[Visual Basic, C#, C++] RenderBeforeContent メソッドをオーバーライドするカスタム HtmlTextWriter クラスの例を次に示します。この例では、 TagKey プロパティの値を使用して、 HtmlTextWriter オブジェクトを使用しているサーバー コントロールが HTML の < label > 要素を出力しているかどうかをチェックします。出力している場合、ラベルのテキストの書式を変更するため、 color 属性が red に設定された < font > 要素が返されます。
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Function RenderBeforeContent() As String
' Check to determine whether the element being rendered
' is a label element. If so, render the opening tag
' of the font element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.Label Then
Return "<font color=""red"">"
Else
Return MyBase.RenderBeforeContent()
End If
End Function 'RenderBeforeContent
[C#]
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override string RenderBeforeContent()
{
// Check to determine whether the element being rendered
// is a label element. If so, render the opening tag
// of the font element; otherwise, call the base method.
if(TagKey == HtmlTextWriterTag.Label)
{
return "<font color=\"red\">";
}
else
{
return base.RenderBeforeContent();
}
}
[C++]
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected:
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
String* RenderBeforeContent() {
// Check to determine whether the element being rendered
// is a label element. If so, render the opening tag
// of the font element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag::Label) {
return S"<font color=\"red\">";
} else {
return __super::RenderBeforeContent();
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
HtmlTextWriter クラス | HtmlTextWriter メンバ | System.Web.UI 名前空間 | TagName