HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Method

Definition

Ruft den Namen des dem angegebenen HtmlTextWriterStyle-Enumerationswert zugeordneten Markupformatattributs ab.Obtains the markup style attribute name associated with the specified HtmlTextWriterStyle enumeration value.

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

Das HtmlTextWriterStyle, für das der Formatattributname abgerufen werden soll.The HtmlTextWriterStyle to obtain the style attribute name for.

Returns

String

Der Formatattributname, der dem in HtmlTextWriterStyle angegebenen styleKey-Enumerationswert zugeordnet ist.The style attribute name associated with the HtmlTextWriterStyle enumeration value specified in styleKey.

Examples

Im folgenden Codebeispiel wird gezeigt, wie Sie überprüfen, ob ein <label> Element gerendert wird.The following code example shows how to check whether a <label> element is being rendered. Wenn dies der Fall ist, wird überprüft, ob ein Color Style-Attribut für das Element definiert wurde.If so, it checks whether a Color style attribute has been defined on the element. Wenn das-Attribut nicht definiert wurde, wird die AddStyleAttribute-Methode aufgerufen, und die GetStyleName-Methode konvertiert den Color-Enumerationsmember in seine Zeichen folgen Darstellung, um Sie an die AddStyleAttribute-Methode zu übergeben.If the attribute has not been defined, the AddStyleAttribute method is called and the GetStyleName method converts the Color enumeration member into its string representation to pass to the AddStyleAttribute method.

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

Remarks

Wenn styleKey kein gültiges HtmlTextWriterStyle Objekt ist, gibt die GetStyleName-Methode eine leere Zeichenfolge ("") zurück.If styleKey is not a valid HtmlTextWriterStyle object, the GetStyleName method returns an empty string ("").

Applies to

See also