HtmlTextWriter.EncodeAttributeValue Método
Definição
Codifica o valor de atributo de marcação especificado com base nos requisitos do objeto HttpRequest do contexto atual.Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.
Sobrecargas
| EncodeAttributeValue(String, Boolean) |
Codifica o valor de atributo de marcação especificado com base nos requisitos do objeto HttpRequest do contexto atual.Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context. |
| EncodeAttributeValue(HtmlTextWriterAttribute, String) |
Codifica o valor de atributo de marcação especificado com base nos requisitos do objeto HttpRequest do contexto atual.Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context. |
EncodeAttributeValue(String, Boolean)
Codifica o valor de atributo de marcação especificado com base nos requisitos do objeto HttpRequest do contexto atual.Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.
protected:
System::String ^ EncodeAttributeValue(System::String ^ value, bool fEncode);
protected string EncodeAttributeValue (string value, bool fEncode);
member this.EncodeAttributeValue : string * bool -> string
Protected Function EncodeAttributeValue (value As String, fEncode As Boolean) As String
Parâmetros
- value
- String
Uma cadeia de caracteres que contém o valor de atributo a codificar.A string containing the attribute value to encode.
- fEncode
- Boolean
true para codificar o valor de atributo; caso contrário, false.true to encode the attribute value; otherwise, false.
Retornos
Uma cadeia de caracteres que contém o valor do atributo codificado, null se value está vazio, ou então o valor do atributo não codificado se fEncode é false.A string containing the encoded attribute value, null if value is empty, or the unencoded attribute value if fEncode is false.
Exemplos
O exemplo de código a seguir mostra como chamar o EncodeAttributeValue método como um parâmetro em uma AddAttribute chamada de método e, em seguida, codifica um valor de atributo de color:blue estilo.The following code example shows how to call the EncodeAttributeValue method as a parameter in an AddAttribute method call, and then encodes a color:blue style attribute value.
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if ( TagKey == HtmlTextWriterTag::Label )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Style ) )
{
AddAttribute( "style", EncodeAttributeValue( "color:blue", true ) );
Write( NewLine );
Indent = 3;
OutputTabs();
}
}
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if (TagKey == HtmlTextWriterTag.Label)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Style))
{
AddAttribute("style", EncodeAttributeValue("color:blue", true));
Write(NewLine);
Indent = 3;
OutputTabs();
}
}
' If the <label> element is rendered and a style
' attribute is not defined, add a style attribute
' and set its value to blue.
If TagKey = HtmlTextWriterTag.Label Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Style) Then
AddAttribute("style", EncodeAttributeValue("color:blue", True))
Write(NewLine)
Indent = 3
OutputTabs()
End If
End If
Comentários
Use a EncodeAttributeValue sobrecarga do EncodeAttributeValue(HtmlTextWriterAttribute, String) método se o atributo não for um HtmlTextWriterAttribute valor de enumeração ou não for conhecido até o tempo de execução.Use the EncodeAttributeValue overload of the EncodeAttributeValue(HtmlTextWriterAttribute, String) method if the attribute is not an HtmlTextWriterAttribute enumeration value or is not known until run time.
O EncodeAttributeValue método remove aspas duplas ("), e comercial (&) e menos de sinais (<) para que as marcas inválidas não sejam geradas, independentemente da entrada.The EncodeAttributeValue method removes double quotation marks ("), ampersands (&), and less than signs (<) so that invalid tags are not generated, regardless of the input. A codificação real é executada pelo HtmlAttributeEncode método.The actual encoding is performed by the HtmlAttributeEncode method.
Confira também
Aplica-se a
EncodeAttributeValue(HtmlTextWriterAttribute, String)
Codifica o valor de atributo de marcação especificado com base nos requisitos do objeto HttpRequest do contexto atual.Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.
protected:
virtual System::String ^ EncodeAttributeValue(System::Web::UI::HtmlTextWriterAttribute attrKey, System::String ^ value);
protected virtual string EncodeAttributeValue (System.Web.UI.HtmlTextWriterAttribute attrKey, string value);
abstract member EncodeAttributeValue : System.Web.UI.HtmlTextWriterAttribute * string -> string
override this.EncodeAttributeValue : System.Web.UI.HtmlTextWriterAttribute * string -> string
Protected Overridable Function EncodeAttributeValue (attrKey As HtmlTextWriterAttribute, value As String) As String
Parâmetros
- attrKey
- HtmlTextWriterAttribute
Um HtmlTextWriterAttribute que representa o atributo de marcação.An HtmlTextWriterAttribute representing the markup attribute.
- value
- String
Uma cadeia de caracteres que contém o valor de atributo a codificar.A string containing the attribute value to encode.
Retornos
Uma cadeia de caracteres que contém o valor de atributo codificado.A string containing the encoded attribute value.
Comentários
O EncodeAttributeValue método remove aspas duplas ("), e comercial (&) e menos de sinais (<) para que as marcas inválidas não sejam geradas, independentemente da entrada.The EncodeAttributeValue method removes double quotation marks ("), ampersands (&), and less than signs (<) so that invalid tags are not generated, regardless of the input. A codificação real é executada pelo HtmlAttributeEncode método.The actual encoding is performed by the HtmlAttributeEncode method.