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 метод . Переопределение проверяет, равно Font ли tagKey поле, что указывает, что <font> элемент разметки будет отрисован. Если да, переопределение вызывает IsAttributeDefined метод , чтобы узнать, содержит Size ли <font> элемент атрибут . 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 или пустую строку (""), или не удается найти в таблице имен атрибутов, возвращается значение -1, введенное HtmlTextWriterAttribute в объект .

Применяется к

См. также раздел