HtmlTextWriter.GetAttributeKey(String) Metoda

Definice

Získá odpovídající HtmlTextWriterAttribute hodnotu výčtu pro zadaný atribut.

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

Parametry

attrName
String

Řetězec, který obsahuje atribut, pro který získat HtmlTextWriterAttribute.

Návraty

Hodnota HtmlTextWriterAttribute výčtu pro zadaný atribut, jinak je neplatná HtmlTextWriterAttribute hodnota, pokud atribut není členem výčtu.

Příklady

Následující příklad kódu ukazuje, jak použít třídu odvozenou z HtmlTextWriter třídy, která přepíše metodu RenderBeginTag . Přepsání zkontroluje, zda tagKey je rovna Font poli, což označuje, že <font> prvek revize bude vykreslen. Pokud ano, přepsání volá metodu IsAttributeDefined zjistit, zda <font> prvek obsahuje Size atribut. Pokud vrátí IsAttributeDefined , metoda volá metodufalse, která definuje AddAttribute a nastaví jeho hodnotu na 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

Poznámky

Pokud attrName je nebo prázdný null řetězec (""), nebo nelze nalézt v tabulce názvů atributů, vrátí se hodnota -1, zadaná do objektu HtmlTextWriterAttribute .

Platí pro

Viz také