HtmlTextWriter.EncodeAttributeValue メソッド

定義

現在のコンテキストの HttpRequest オブジェクトの要件に基づいて、指定したマークアップ属性の値をエンコードします。

オーバーロード

名前 説明
EncodeAttributeValue(String, Boolean)

現在のコンテキストの HttpRequest オブジェクトの要件に基づいて、指定したマークアップ属性の値をエンコードします。

EncodeAttributeValue(HtmlTextWriterAttribute, String)

現在のコンテキストの HttpRequest オブジェクトの要件に基づいて、指定したマークアップ属性の値をエンコードします。

EncodeAttributeValue(String, Boolean)

現在のコンテキストの HttpRequest オブジェクトの要件に基づいて、指定したマークアップ属性の値をエンコードします。

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

エンコードする属性値を含む文字列。

fEncode
Boolean

true 属性値をエンコードする場合。それ以外の場合は false

返品

エンコードされた属性値を含む文字列。valueが空の場合はnullfEncodefalse場合はエンコードされていない属性値。

次のコード例は、AddAttribute メソッド呼び出しでパラメーターとして EncodeAttributeValue メソッドを呼び出し、color:blue スタイルの属性値をエンコードする方法を示しています。

// 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

注釈

属性がHtmlTextWriterAttribute列挙値でない場合、または実行時まで不明な場合は、EncodeAttributeValue(HtmlTextWriterAttribute, String) メソッドのEncodeAttributeValueオーバーロードを使用します。

EncodeAttributeValue メソッドは、二重引用符 (")、アンパサンド (>)、および小さい符号 (<) を削除して、入力に関係なく無効なタグが生成されないようにします。 実際のエンコードは、 HtmlAttributeEncode メソッドによって実行されます。

こちらもご覧ください

適用対象

EncodeAttributeValue(HtmlTextWriterAttribute, String)

現在のコンテキストの HttpRequest オブジェクトの要件に基づいて、指定したマークアップ属性の値をエンコードします。

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

パラメーター

attrKey
HtmlTextWriterAttribute

マークアップ属性を表す HtmlTextWriterAttribute

value
String

エンコードする属性値を含む文字列。

返品

エンコードされた属性値を含む文字列。

注釈

EncodeAttributeValue メソッドは、二重引用符 (")、アンパサンド (>)、および小さい符号 (<) を削除して、入力に関係なく無効なタグが生成されないようにします。 実際のエンコードは、 HtmlAttributeEncode メソッドによって実行されます。

こちらもご覧ください

適用対象