HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Metodo

Definizione

Ottiene il nome dell'attributo dello stile di markup associato al valore di enumerazione specificato HtmlTextWriterStyle .

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

Parametri

styleKey
HtmlTextWriterStyle

Oggetto HtmlTextWriterStyle per cui ottenere il nome dell'attributo di stile.

Valori restituiti

Nome dell'attributo di stile associato al HtmlTextWriterStyle valore di enumerazione specificato in styleKey.

Esempio

Nell'esempio di codice seguente viene illustrato come verificare se viene eseguito il rendering di un <label> elemento. In tal caso, controlla se un Color attributo di stile è stato definito nell'elemento . Se l'attributo non è stato definito, viene chiamato il AddStyleAttribute metodo e il GetStyleName metodo converte il Color membro di enumerazione nella relativa rappresentazione di stringa da passare al AddStyleAttribute metodo .

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

Commenti

Se styleKey non è un oggetto valido HtmlTextWriterStyle , il GetStyleName metodo restituisce una stringa vuota ("").

Si applica a

Vedi anche