HtmlTextWriter.GetAttributeKey(String) 方法

定義

取得指定屬性對應 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值。

範例

以下程式碼範例示範如何使用由該 HtmlTextWriter 類別衍生的類別來覆蓋該 RenderBeginTag 方法。 覆寫會 tagKey 檢查 是否等於欄位, Font 表示 <font> 將呈現標記元素。 如果是這樣,覆寫會呼叫該 IsAttributeDefined 方法來判斷該 <font> 元素是否包含屬性 Size 。 若回傳 ,IsAttributeDefined方法呼叫falseAddAttribute方法,該方法定義 ,GetAttributeKey並將值設為 Size30pt

// 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

備註

attrNamenull 空字串(“”),或在屬性名稱表中找不到,則回傳物件的 HtmlTextWriterAttribute 值 -1(輸入物件)。

適用於

另請參閱