HtmlTextWriter.GetAttributeKey(String) Metoda

Definicja

Uzyskuje odpowiednią HtmlTextWriterAttribute wartość wyliczenia dla określonego atrybutu.

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

Ciąg zawierający atrybut, dla którego ma być uzyskiwany HtmlTextWriterAttributeelement .

Zwraca

Wartość HtmlTextWriterAttribute wyliczenia określonego atrybutu; w przeciwnym razie nieprawidłowa HtmlTextWriterAttribute wartość, jeśli atrybut nie jest elementem członkowskim wyliczenia.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać klasy pochodzącej HtmlTextWriter z klasy, która zastępuje metodę RenderBeginTag . Przesłonięcia sprawdza, czy tagKey jest równe Font polu, co oznacza, że <font> element znaczników zostanie renderowany. Jeśli tak, przesłonięcia wywołuje metodę IsAttributeDefined , aby dowiedzieć się, czy <font> element zawiera Size atrybut. IsAttributeDefined Jeśli metoda zwraca falsewartość , AddAttribute metoda wywołuje metodę , która definiuje Size metodę GetAttributeKey i ustawia jej wartość na 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

Uwagi

Jeśli attrName jest null lub pusty ciąg (""), lub nie można go znaleźć w tabeli nazw atrybutów, wartość -1, typizowane do HtmlTextWriterAttribute obiektu, jest zwracany.

Dotyczy

Zobacz też