HtmlTextWriter.GetAttributeKey(String) HtmlTextWriter.GetAttributeKey(String) HtmlTextWriter.GetAttributeKey(String) HtmlTextWriter.GetAttributeKey(String) Method

定義

取得指定屬性的對應 HtmlTextWriterAttribute 列舉值。Obtains the corresponding HtmlTextWriterAttribute enumeration value for the specified attribute.

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

字串,包含要取得的 HtmlTextWriterAttribute 之屬性。A string that contains the attribute for which to obtain the HtmlTextWriterAttribute.

傳回

指定屬性的 HtmlTextWriterAttribute 列舉值,如果該屬性不是列舉型別的成員,則為無效的 HtmlTextWriterAttribute 值。The HtmlTextWriterAttribute enumeration value for the specified attribute; otherwise, an invalid HtmlTextWriterAttribute value if the attribute is not a member of the enumeration.

範例

下列程式碼範例示範如何使用衍生自HtmlTextWriter類別的類別,它會RenderBeginTag覆寫方法。The following code example demonstrates how to use a class, derived from the HtmlTextWriter class, that overrides the RenderBeginTag method. 覆寫會檢查tagKey是否等於Font欄位<font> ,這表示將會呈現標記專案。The override checks whether tagKey is equal to the Font field, which indicates that a <font> markup element will be rendered. 若是如此,覆寫就會IsAttributeDefined呼叫方法來找出<font>元素是否包含Size屬性。If so, the override calls the IsAttributeDefined method to find out whether the <font> element contains a Size attribute. IsAttributeDefined 如果傳回GetAttributeKey 30pt,則AddAttribute 方法會呼叫方法,它會定義,並將其Size值設定為。 falseIf the IsAttributeDefined returns false, the AddAttribute method calls the GetAttributeKey method, which defines the Size and sets its value to 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 HtmlTextWriterAttributenull或空字串(""),或在屬性名稱的資料表中找不到,則會傳回值-1 (輸入物件)。If attrName is null or an empty string (""), or cannot be found in the table of attribute names, the value -1, typed to an HtmlTextWriterAttribute object, is returned.

適用於

另請參閱