HtmlTextWriter.GetAttributeKey(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した属性の対応する HtmlTextWriterAttribute 列挙値を取得します。
protected:
System::Web::UI::HtmlTextWriterAttribute GetAttributeKey(System::String ^ attrName);
protected System.Web.UI.HtmlTextWriterAttribute GetAttributeKey(string attrName);
member this.GetAttributeKey : string -> System.Web.UI.HtmlTextWriterAttribute
Protected Function GetAttributeKey (attrName As String) As HtmlTextWriterAttribute
パラメーター
- attrName
- String
HtmlTextWriterAttributeを取得する属性を含む文字列。
返品
指定した属性の HtmlTextWriterAttribute 列挙値。それ以外の場合、属性が列挙体のメンバーでない場合は無効な HtmlTextWriterAttribute 値です。
例
次のコード例では、RenderBeginTag メソッドをオーバーライドする、HtmlTextWriter クラスから派生したクラスを使用する方法を示します。 オーバーライドは、 tagKey が Font フィールドと等しいかどうかをチェックします。これは、 <font> マークアップ要素がレンダリングされることを示します。 その場合、オーバーライドは IsAttributeDefined メソッドを呼び出して、 <font> 要素に Size 属性が含まれているかどうかを調べます。
IsAttributeDefinedがfalseを返す場合、AddAttribute メソッドは GetAttributeKey メソッドを呼び出します。このメソッドは、Sizeを定義し、その値を 30pt に設定します。
// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point.
if ( tagKey == HtmlTextWriterTag::Font )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Size ) )
{
AddAttribute( GetAttributeKey( "size" ), "30pt" );
}
}
// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point.
if (tagKey == HtmlTextWriterTag.Font)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Size))
{
AddAttribute(GetAttributeKey("size"), "30pt");
}
}
' If the tagKey parameter is set to a <font> element
' but a size attribute is not defined on the element,
' the AddStyleAttribute method adds a size attribute
' and sets it to 30 point.
If tagKey = HtmlTextWriterTag.Font Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then
AddAttribute(GetAttributeKey("size"), "30pt")
End If
End If
注釈
attrNameがnullまたは空の文字列 ("") であるか、属性名のテーブルに見つからない場合は、HtmlTextWriterAttribute オブジェクトに型指定された値 -1 が返されます。