HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o nome do atributo estilo de marcação associado ao valor de enumeração especificado 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
Parâmetros
- styleKey
- HtmlTextWriterStyle
O HtmlTextWriterStyle para obter o nome do atributo de estilo para.
Devoluções
O nome do atributo style associado ao HtmlTextWriterStyle valor de enumeração especificado em styleKey.
Exemplos
O exemplo de código seguinte mostra como verificar se um <label> elemento está a ser renderizado. Se sim, verifica se um Color atributo de estilo foi definido no elemento. Se o atributo não tiver sido definido, o AddStyleAttribute método é chamado e o GetStyleName método converte o Color membro de enumeração na sua representação de cadeia para passar ao 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
Observações
Se styleKey não for um objeto válido HtmlTextWriterStyle , o GetStyleName método devolve uma cadeia vazia ("").