属性をマークアップとして表示する HtmlTextWriter オブジェクトに AttributeCollection クラスの属性を追加します。
名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public Sub AddAttributes ( _
writer As HtmlTextWriter _
)
'使用
Dim instance As AttributeCollection
Dim writer As HtmlTextWriter
instance.AddAttributes(writer)
public void AddAttributes (
HtmlTextWriter writer
)
public:
void AddAttributes (
HtmlTextWriter^ writer
)
public void AddAttributes (
HtmlTextWriter writer
)
public function AddAttributes (
writer : HtmlTextWriter
)
適用できません。
パラメータ
- writer
ASP.NET サーバー コントロールの開始タグに属性を書き込む HtmlTextWriter インスタンス。
解説
このメソッドはサーバー コントロールのすべての属性を HtmlTextWriter オブジェクトにコピーし、次回の RenderBeginTag メソッドの呼び出しで表示されるようにします。
Calendar や CheckBoxList などの他のコントロールに含まれているコントロールの場合、含まれているコントロールを直接表示することによって、パフォーマンスが向上する場合があります。直接表示は、コンテナ コントロールを介した表示よりも高速です。コンテナ コントロールでは、すべての子コントロール属性をコンテナ コントロールにコピーし、コピー時に 1 回表示する必要があるからです。
使用例
新しい属性を Button サーバー コントロール myButton
と TextBox サーバー コントロール myTextBox
に追加し、次にこれらの属性をカスタム HtmlTextWriter に追加し、これらの属性をコントロールの各出力ストリームに書き込む例を次に示します。
myButton.Attributes.Clear()
myTextBox.Attributes.Clear()
myButton.Attributes("onClick") = "javascript:alert('Visiting msn.com');"
myTextBox.Attributes("name") = "MyTextBox"
myTextBox.Attributes("onBlur") = "javascript:alert('Leaving MyTextBox...');"
Dim myHttpResponse As HttpResponse = Response
Dim myHtmlTextWriter As New HtmlTextWriter(myHttpResponse.Output)
myButton.Attributes.AddAttributes(myHtmlTextWriter)
myTextBox.Attributes.AddAttributes(myHtmlTextWriter)
myButton.Attributes.Clear();
myTextBox.Attributes.Clear();
myButton.Attributes["onClick"] =
"javascript:alert('Visiting msn.com');";
myTextBox.Attributes["name"] = "MyTextBox";
myTextBox.Attributes["onBlur"] =
"javascript:alert('Leaving MyTextBox...');";
HttpResponse myHttpResponse = Response;
HtmlTextWriter myHtmlTextWriter =
new HtmlTextWriter(myHttpResponse.Output);
myButton.Attributes.AddAttributes(myHtmlTextWriter);
myTextBox.Attributes.AddAttributes(myHtmlTextWriter);
myButton.get_Attributes().Clear();
myTextBox.get_Attributes().Clear();
myButton.get_Attributes().set_Item("onClick",
"javascript:alert('Visiting msn.com');");
myTextBox.get_Attributes().set_Item("name","MyTextBox");
myTextBox.get_Attributes().set_Item("onBlur",
"javascript:alert('Leaving MyTextBox...');");
HttpResponse myHttpResponse = get_Response();
HtmlTextWriter myHtmlTextWriter = new HtmlTextWriter(myHttpResponse.
get_Output());
myButton.get_Attributes().AddAttributes(myHtmlTextWriter);
myTextBox.get_Attributes().AddAttributes(myHtmlTextWriter);
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
AttributeCollection クラス
AttributeCollection メンバ
System.Web.UI 名前空間
RenderBeginTag