HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Método

Definición

Obtiene el atributo de estilo de marcado asociado al valor de la enumeración HtmlTextWriterStyle especificado.

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

Parámetros

styleKey
HtmlTextWriterStyle

HtmlTextWriterStyle para el que se va a obtener el nombre del atributo de estilo.

Devoluciones

Nombre del atributo de estilo de marcado asociado al valor de la enumeración HtmlTextWriterStyle especificado en styleKey.

Ejemplos

En el ejemplo de código siguiente se muestra cómo comprobar si se representa un <label> elemento. Si es así, comprueba si se ha definido un Color atributo de estilo en el elemento . Si no se ha definido el atributo , se llama al AddStyleAttribute método y el GetStyleName método convierte el Color miembro de enumeración en su representación de cadena para pasar al AddStyleAttribute método .

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

Comentarios

Si styleKey no es un objeto válido HtmlTextWriterStyle , el GetStyleName método devuelve una cadena vacía ("").

Se aplica a

Consulte también