HtmlTextWriter.EncodeAttributeValue HtmlTextWriter.EncodeAttributeValue HtmlTextWriter.EncodeAttributeValue HtmlTextWriter.EncodeAttributeValue Method

定義

根據目前內容中 HttpRequest 物件的需求來編碼指定標記屬性的值。Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.

多載

EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean)

根據目前內容中 HttpRequest 物件的需求來編碼指定標記屬性的值。Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.

EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String)

根據目前內容中 HttpRequest 物件的需求來編碼指定標記屬性的值。Encodes the value of the specified markup attribute based on the requirements of the HttpRequest object of the current context.

EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean) EncodeAttributeValue(String, Boolean)

根據目前內容中 HttpRequest 物件的需求來編碼指定標記屬性的值。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

參數

value
String String String String

包含要編碼的屬性值的字串。A string containing the attribute value to encode.

fEncode
Boolean Boolean Boolean Boolean

true 表示要編碼屬性值;否則為 falsetrue to encode the attribute value; otherwise, false.

傳回

包含已編碼屬性值的字串、如果 value 是空的則為 null,或者如果 fEncodefalse,則為未編碼的屬性值。A string containing the encoded attribute value, null if value is empty, or the unencoded attribute value if fEncode is false.

範例

下列程式碼範例示範如何呼叫EncodeAttributeValue方法做為AddAttribute方法呼叫中的參數color:blue ,然後將樣式屬性值編碼。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

備註

如果屬性EncodeAttributeValueEncodeAttributeValue(HtmlTextWriterAttribute, String)是列舉值,或在執行時間之前不知道,請使用方法的多載。 HtmlTextWriterAttributeUse 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.

EncodeAttributeValue方法會移除雙引號(")、符號(&)和小於符號(<),因此不論輸入為何,都不會產生不正確標記。The EncodeAttributeValue method removes double quotation marks ("), ampersands (&), and less than signs (<) so that invalid tags are not generated, regardless of the input. 實際的編碼是由HtmlAttributeEncode方法執行。The actual encoding is performed by the HtmlAttributeEncode method.

另請參閱

EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String) EncodeAttributeValue(HtmlTextWriterAttribute, String)

根據目前內容中 HttpRequest 物件的需求來編碼指定標記屬性的值。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

參數

value
String String String String

包含要編碼的屬性值的字串。A string containing the attribute value to encode.

傳回

字串,包含已編碼的屬性值。A string containing the encoded attribute value.

備註

EncodeAttributeValue方法會移除雙引號(")、符號(&)和小於符號(<),因此不論輸入為何,都不會產生不正確標記。The EncodeAttributeValue method removes double quotation marks ("), ampersands (&), and less than signs (<) so that invalid tags are not generated, regardless of the input. 實際的編碼是由HtmlAttributeEncode方法執行。The actual encoding is performed by the HtmlAttributeEncode method.

另請參閱

適用於