HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Metoda

Definicja

Uzyskuje nazwę atrybutu stylu znaczników skojarzone z określoną HtmlTextWriterStyle wartością wyliczenia.

C#
protected string GetStyleName (System.Web.UI.HtmlTextWriterStyle styleKey);

Parametry

styleKey
HtmlTextWriterStyle

Aby HtmlTextWriterStyle uzyskać nazwę atrybutu stylu dla.

Zwraca

String

Nazwa atrybutu stylu skojarzona z wartością HtmlTextWriterStyle wyliczenia określoną w pliku styleKey.

Przykłady

Poniższy przykład kodu pokazuje, jak sprawdzić, czy <label> element jest renderowany. Jeśli tak, sprawdza, czy Color atrybut stylu został zdefiniowany w elemecie . Jeśli atrybut nie został zdefiniowany, metoda jest wywoływana, AddStyleAttribute a GetStyleName metoda konwertuje Color element członkowski wyliczenia na jego reprezentację ciągu w celu przekazania do AddStyleAttribute metody .

C#
// If the markup element being rendered is a Label,
// render the opening tag of a Font element before it.
if (tagKey == HtmlTextWriterTag.Label)
{
    // Check whether a Color style attribute is 
    // included on the Label. If not, use the
    // AddStyleAttribute and GetStyleName methods to add one
    // and set its value to red.
    if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color))
    {
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red");
    }

Uwagi

Jeśli styleKey nie jest prawidłowym HtmlTextWriterStyle obiektem, GetStyleName metoda zwraca pusty ciąg ("").

Dotyczy

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

Zobacz też