Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.
Assembly: System.Web (in System.Web.dll)
Protected Function EncodeAttributeValue ( _ value As String, _ fEncode As Boolean _ ) As String
protected string EncodeAttributeValue( string value, bool fEncode )
protected: String^ EncodeAttributeValue( String^ value, bool fEncode )
member EncodeAttributeValue : value:string * fEncode:bool -> string
Parameters
- value
- Type: System.String
A string containing the attribute value to encode.
- fEncode
- Type: System.Boolean
true to encode the attribute value; otherwise, false.
Return Value
Type: System.StringA string containing the encoded attribute value, null if value is empty, or the unencoded attribute value if fEncode is false.
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.
The EncodeAttributeValue method removes double quotation marks ("), ampersands (&), and less than signs (<) so that invalid tags are not generated, regardless of the input. The actual encoding is performed by the HtmlAttributeEncode method.
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 Then If Not IsAttributeDefined(HtmlTextWriterAttribute.Style) Then AddAttribute("style", EncodeAttributeValue("color:blue", True)) Write(NewLine) Indent = 3 OutputTabs() End If End If
// 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(); } }
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.