HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Methode

Definitie

Hiermee haalt u de kenmerknaam van de markeringsstijl op die is gekoppeld aan de opgegeven HtmlTextWriterStyle opsommingswaarde.

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

Parameters

styleKey
HtmlTextWriterStyle

De HtmlTextWriterStyle naam van het stijlkenmerk voor ophalen.

Retouren

De naam van het stijlkenmerk dat is gekoppeld aan de HtmlTextWriterStyle opsommingswaarde die is opgegeven in styleKey.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u kunt controleren of een <label> element wordt weergegeven. Zo ja, dan wordt gecontroleerd of er een Color stijlkenmerk is gedefinieerd voor het element. Als het kenmerk niet is gedefinieerd, wordt de AddStyleAttribute methode aangeroepen en converteert de GetStyleName methode het opsommingslid naar de Color tekenreeksweergave om door te geven aan de AddStyleAttribute methode.

// 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

Opmerkingen

Als styleKey dit een HtmlTextWriterStyle ongeldig object is, retourneert de GetStyleName methode een lege tekenreeks ("").

Van toepassing op

Zie ook