HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Metod

Definition

Hämtar det attributnamn för markeringsformat som är associerat med det angivna HtmlTextWriterStyle uppräkningsvärdet.

protected:
 System::String ^ GetStyleName(System::Web::UI::HtmlTextWriterStyle styleKey);
protected string GetStyleName(System.Web.UI.HtmlTextWriterStyle styleKey);
member this.GetStyleName : System.Web.UI.HtmlTextWriterStyle -> string
Protected Function GetStyleName (styleKey As HtmlTextWriterStyle) As String

Parametrar

styleKey
HtmlTextWriterStyle

För HtmlTextWriterStyle att hämta formatattributnamnet för.

Returer

Formatattributnamnet som är associerat med uppräkningsvärdet HtmlTextWriterStyle som anges i styleKey.

Exempel

I följande kodexempel visas hur du kontrollerar om ett <label> element återges. I så fall kontrollerar den om ett Color formatattribut har definierats för elementet. Om attributet inte har definierats anropas AddStyleAttribute metoden och GetStyleName metoden konverterar uppräkningsmedlemmen Color till dess strängrepresentation för att skicka till AddStyleAttribute metoden.

// 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" );
   }
// 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");
    }
' If the markup element being rendered is a Label,
' render the opening tag of a Font element before it.
If tagKey = HtmlTextWriterTag.Label Then
    ' 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 Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red")
    End If

Kommentarer

Om styleKey inte är ett giltigt HtmlTextWriterStyle objekt GetStyleName returnerar metoden en tom sträng ("").

Gäller för

Se även