HtmlTextWriter.AddStyleAttribute 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.
Adiciona um atributo de estilo de marcação à etiqueta de abertura do elemento que o HtmlTextWriter objeto cria com uma chamada subsequente ao RenderBeginTag método.
Sobrecargas
| Name | Description |
|---|---|
| AddStyleAttribute(String, String) |
Adiciona o atributo de estilo de marcação especificado e o valor do atributo à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método. |
| AddStyleAttribute(HtmlTextWriterStyle, String) |
Adiciona o atributo de estilo de marcação associado ao valor especificado HtmlTextWriterStyle e o valor do atributo à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método. |
| AddStyleAttribute(String, String, HtmlTextWriterStyle) |
Adiciona o atributo de estilo de marcação especificado e o valor do atributo, juntamente com um HtmlTextWriterStyle valor de enumeração, à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método. |
AddStyleAttribute(String, String)
Adiciona o atributo de estilo de marcação especificado e o valor do atributo à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método.
public:
virtual void AddStyleAttribute(System::String ^ name, System::String ^ value);
public virtual void AddStyleAttribute(string name, string value);
abstract member AddStyleAttribute : string * string -> unit
override this.AddStyleAttribute : string * string -> unit
Public Overridable Sub AddStyleAttribute (name As String, value As String)
Parâmetros
- name
- String
Uma cadeia que contenha o atributo estilo a adicionar.
- value
- String
Uma cadeia que contém o valor a atribuir ao atributo.
Exemplos
O exemplo de código seguinte mostra como usar a RenderBeginTag sobrecarga do AddStyleAttribute(String, String) método para renderizar font-size e color estilizar atributos num <p> elemento. Este exemplo de código usa a HtmlTextWriter classe para renderizar o conteúdo do controlo.
// Add style attribute for 'p'(paragraph) element.
writer->AddStyleAttribute( "font-size", "12pt" );
writer->AddStyleAttribute( "color", "fuchsia" );
// Output the 'p' (paragraph) element with the style attributes.
writer->RenderBeginTag( "p" );
// Output the 'Message' property contents and the time on the server.
writer->Write( String::Concat( Message, "<br>",
"The time on the server: ",
System::DateTime::Now.ToLongTimeString() ) );
// Close the element.
writer->RenderEndTag();
// Add style attribute for 'p'(paragraph) element.
writer.AddStyleAttribute("font-size", "12pt");
writer.AddStyleAttribute("color", "fuchsia");
// Output the 'p' (paragraph) element with the style attributes.
writer.RenderBeginTag("p");
// Output the 'Message' property contents and the time on the server.
writer.Write(Message + "<br>" +
"The time on the server: " +
System.DateTime.Now.ToLongTimeString());
// Close the element.
writer.RenderEndTag();
'Add style attribute for 'p'(paragraph) element.
writer.AddStyleAttribute("font-size", "12pt")
writer.AddStyleAttribute("color", "fuchsia")
'Output the 'p' (paragraph) element with the style attributes.
writer.RenderBeginTag("p")
'Output the 'Message' property contents and the time on the server.
writer.Write((Message & "<br>" & "The time on the server: " & _
System.DateTime.Now.ToLongTimeString()))
' Close the element.
writer.RenderEndTag()
Observações
Use a AddStyleAttribute sobrecarga do AddStyleAttribute(String, String) método quando o estilo não é membro da HtmlTextWriterStyle enumeração ou só é conhecido em tempo de execução.
A HtmlTextWriter classe mantém uma lista de estilos para os elementos de marcação que renderiza. Quando o RenderBeginTag método é chamado, quaisquer estilos adicionados pelo AddStyleAttribute método são renderizados para a etiqueta de abertura do elemento. A lista de estilos é então limpa.
O padrão de codificação para renderizar elementos de marcação é o seguinte:
Use o AddStyleAttribute método para adicionar quaisquer atributos de estilo ao elemento.
Use o método RenderBeginTag.
Use outros métodos conforme necessário para renderizar o conteúdo encontrado entre as etiquetas de abertura e fecho dos elementos.
Use o método RenderEndTag.
Ver também
Aplica-se a
AddStyleAttribute(HtmlTextWriterStyle, String)
Adiciona o atributo de estilo de marcação associado ao valor especificado HtmlTextWriterStyle e o valor do atributo à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método.
public:
virtual void AddStyleAttribute(System::Web::UI::HtmlTextWriterStyle key, System::String ^ value);
public virtual void AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle key, string value);
abstract member AddStyleAttribute : System.Web.UI.HtmlTextWriterStyle * string -> unit
override this.AddStyleAttribute : System.Web.UI.HtmlTextWriterStyle * string -> unit
Public Overridable Sub AddStyleAttribute (key As HtmlTextWriterStyle, value As String)
Parâmetros
E HtmlTextWriterStyle que representa o atributo estilo a adicionar ao fluxo de saída.
- value
- String
Uma cadeia que contém o valor a atribuir ao atributo.
Exemplos
O exemplo de código seguinte demonstra como usar parte de um override do RenderBeginTag método numa classe derivada da HtmlTextWriter classe. O código verifica se um <Label> elemento está a ser renderizado. Se assim for, o IsStyleAttributeDefined método é chamado para verificar se um Color atributo de estilo foi definido para o <Label> elemento. Se um Color atributo não tiver sido definido, o código chama esta sobrecarga do AddStyleAttribute método para adicionar o Color atributo ao atributo style, e depois definir o seu valor para 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)
{
// 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
Use a AddStyleAttribute sobrecarga do AddStyleAttribute(HtmlTextWriterStyle, String) método quando o estilo é membro da HtmlTextWriterStyle enumeração e é conhecido antes do tempo de execução.
A HtmlTextWriter classe mantém uma lista de estilos para os elementos de marcação que renderiza. Quando o RenderBeginTag método é chamado, quaisquer estilos adicionados pelo AddStyleAttribute método são renderizados para a etiqueta de abertura do elemento. A lista de estilos é então limpa.
O padrão de codificação para renderizar elementos de marcação é o seguinte:
Use o AddStyleAttribute método para adicionar quaisquer atributos de estilo ao elemento.
Use o método RenderBeginTag.
Use outros métodos conforme necessário para renderizar o conteúdo encontrado entre as etiquetas de abertura e fecho dos elementos.
Use o método RenderEndTag.
Ver também
Aplica-se a
AddStyleAttribute(String, String, HtmlTextWriterStyle)
Adiciona o atributo de estilo de marcação especificado e o valor do atributo, juntamente com um HtmlTextWriterStyle valor de enumeração, à etiqueta de marcação de abertura criada por uma chamada subsequente ao RenderBeginTag método.
protected:
virtual void AddStyleAttribute(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterStyle key);
protected virtual void AddStyleAttribute(string name, string value, System.Web.UI.HtmlTextWriterStyle key);
abstract member AddStyleAttribute : string * string * System.Web.UI.HtmlTextWriterStyle -> unit
override this.AddStyleAttribute : string * string * System.Web.UI.HtmlTextWriterStyle -> unit
Protected Overridable Sub AddStyleAttribute (name As String, value As String, key As HtmlTextWriterStyle)
Parâmetros
- name
- String
Uma cadeia que contenha o atributo estilo a ser adicionado.
- value
- String
Uma cadeia que contém o valor a atribuir ao atributo.
Um HtmlTextWriterStyle que representa o atributo estilo a adicionar.
Observações
Use a AddStyleAttribute sobrecarga do AddStyleAttribute(String, String, HtmlTextWriterStyle) método apenas quando herdar da HtmlTextWriter turma. Permite-te criar novos name e value pares para HtmlTextWriterStyle atributos.