ConnectionConsumerAttribute クラス
アセンブリ: System.Web (system.web.dll 内)

<AttributeUsageAttribute(AttributeTargets.Method)> _ Public Class ConnectionConsumerAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Method)] public class ConnectionConsumerAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)] public ref class ConnectionConsumerAttribute : public Attribute

Web パーツ接続は WebPartZoneBase ゾーン内に存在する 2 つのサーバー コントロールで構成され、一方のコントロールからもう一方に渡されるインターフェイス インスタンスを使用してデータを共有します。インターフェイス インスタンスを渡すコントロールはプロバイダと呼ばれ、インターフェイス インスタンスを受け取ってデータの処理または表示を行うコントロールはコンシューマと呼ばれます。接続の詳細については、WebPartConnection クラスのトピックおよび「Web パーツ接続の概要」を参照してください。
接続のコンシューマ コントロールには WebPart コントロール、任意の種類のサーバー コントロール、ユーザー コントロールのいずれかを使用できますが、これらはコールバック メソッドとして指定されたメソッドを持っている必要があります。コールバック メソッドは接続処理を実行しているときに呼び出され、その目的はデータが格納されたインターフェイス インスタンスをプロバイダから受け取ることにあります。コンシューマでコールバック メソッドとしての役割を果たすメソッドを指定するには、ConnectionConsumerAttribute メタデータ要素をメソッドに追加する必要があります (この要素は ConnectionConsumerAttribute クラスに基づいています)。
ConnectionConsumerAttribute オブジェクトを使用すると、コンシューマのコールバック メソッドを指定することに加え、コンシューマのコネクション ポイントに関する特定の詳細を指定することもできます。コンシューマ接続ポイントは、ConsumerConnectionPoint クラスのインスタンスです。このクラスは、コンシューマのコントロールの種類、同時に複数のプロバイダに接続できるかどうか、コンシューマがプロバイダから受け取ることのできるインターフェイスの種類、コールバック メソッドに関する詳細、ユーザー インターフェイス (UI) でコンシューマ接続ポイントを表す表示名など、接続の確立に必要なコンシューマに関するすべての詳細をカプセル化します。すべての Web パーツ接続には、コンシューマ コントロールに関連付けられたコンシューマ接続ポイントが含まれます。
コンシューマのコールバック メソッドに ConnectionConsumerAttribute メタデータ要素を追加すると、それを使用してコンシューマ接続ポイントに関する詳細を指定することもできます。この詳細には、コネクション ポイントの表示名 (詳細については、DisplayName プロパティのトピックを参照)、コンシューマが同時に複数のプロバイダに接続できるかどうか (詳細については、AllowsMultipleConnections プロパティのトピックを参照)、コネクション ポイントの ID (詳細については、ID プロパティのトピックを参照)、およびコンシューマが使用するコネクション ポイントの種類 (詳細については、ConnectionPointType プロパティのトピックを参照) があります。ConnectionConsumerAttribute クラスのコンストラクタの 4 つのオーバーロードそれぞれが、クラスの新しいインスタンスを作成するときに 1 つ以上のコネクション ポイント プロパティの値を指定できるパラメータを持ちます。コンシューマ接続ポイントの大部分のプロパティはプログラムで設定することもできるため、ConnectionConsumerAttribute 要素を使用した設定方法は省略できます。
![]() |
---|
コンシューマのコールバック メソッドに ConnectionConsumerAttribute メタデータ要素を追加する場合、常に指定が必要な必須パラメータは displayName パラメータだけです (詳細については、ConnectionConsumerAttribute(String) コンストラクタ オーバーロードのトピックを参照してください)。このパラメータの値は DisplayName プロパティに割り当てられ、ConnectionsZone コントロールで作成された接続 UI を開くと、表示名がその UI でのコンシューマ接続ポイントを表します。1 つのコンシューマ コントロールに複数のコールバック メソッドを指定する場合は、複数のコネクション ポイントから選択できます。また、各コールバック メソッドに ConnectionConsumerAttribute メタデータ要素を追加する際には、それぞれのコンシューマ接続ポイントが既知で一意の ID を持つように id パラメータの値を指定する必要があります。 |

ConnectionConsumerAttribute クラスを使用するコード例を次に示します。ここでは、コンシューマ コントロールのコールバック メソッドで ConnectionConsumerAttribute メタデータ要素を宣言する方法を示しています。コンストラクタの最も簡単なオーバーロードを使用し、displayName パラメータ値だけを渡します。
<ConnectionConsumer("Row")> _ Public Sub SetConnectionInterface(ByVal provider As IWebPartRow) _provider = provider End Sub 'SetConnectionInterface
[ConnectionConsumer("Row")] public void SetConnectionInterface(IWebPartRow provider) { _provider = provider; }
WebPartConnection クラスを使用して、2 つの Web パーツ コントロール間で基本的な静的接続を作成する方法を次のコード例に示します。プロバイダとコンシューマのコード ファイルは、.aspx ページが格納されたアプリケーション フォルダの下にある App_Code フォルダに格納する必要があります。
Imports System Imports System.Collections Imports System.ComponentModel Imports System.Data Imports System.Reflection Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts 'This sample code creates a Web Parts control that acts as a provider of row data. Namespace MyCustomWebPart Public NotInheritable Class RowProviderWebPart Inherits WebPart Implements IWebPartRow Private _table As DataTable Public Sub New() _table = New DataTable() Dim col As New DataColumn() col.DataType = GetType(String) col.ColumnName = "Name" _table.Columns.Add(col) col = New DataColumn() col.DataType = GetType(String) col.ColumnName = "Address" _table.Columns.Add(col) col = New DataColumn() col.DataType = GetType(Integer) col.ColumnName = "ZIP Code" _table.Columns.Add(col) Dim row As DataRow = _table.NewRow() row("Name") = "John Q. Public" row("Address") = "123 Main Street" row("ZIP Code") = 98000 _table.Rows.Add(row) End Sub 'New <ConnectionProvider("Row")> _ Public Function GetConnectionInterface() As IWebPartRow Return New RowProviderWebPart() End Function 'GetConnectionInterface Public ReadOnly Property Schema() As PropertyDescriptorCollection _ Implements IWebPartRow.Schema Get Return TypeDescriptor.GetProperties(_table.DefaultView(0)) End Get End Property Public Sub GetRowData(ByVal callback As RowCallback) _ Implements IWebPartRow.GetRowData callback(_table.Rows) End Sub 'GetRowData
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Reflection; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; //This sample code creates a Web Parts control that acts as a provider of row data. namespace My { public sealed class RowProviderWebPart : WebPart, IWebPartRow { private DataTable _table; public RowProviderWebPart() { _table = new DataTable(); DataColumn col = new DataColumn(); col.DataType = typeof(string); col.ColumnName = "Name"; _table.Columns.Add(col); col = new DataColumn(); col.DataType = typeof(string); col.ColumnName = "Address"; _table.Columns.Add(col); col = new DataColumn(); col.DataType = typeof(int); col.ColumnName = "ZIP Code"; _table.Columns.Add(col); DataRow row = _table.NewRow(); row["Name"] = "John Q. Public"; row["Address"] = "123 Main Street"; row["ZIP Code"] = 98000; _table.Rows.Add(row); } [ConnectionProvider("Row")] public IWebPartRow GetConnectionInterface() { return new RowProviderWebPart(); } public PropertyDescriptorCollection Schema { get { return TypeDescriptor.GetProperties(_table.DefaultView[0]); } } public void GetRowData(RowCallback callback) { callback(_table.Rows); } } }
2 番目の例は、コンシューマとして動作するクラスを示します。メソッドは、ConnectionConsumerAttribute メタデータ要素を持つコールバック メソッドとして指定されています。
Imports System Imports System.Collections Imports System.ComponentModel Imports System.Data Imports System.Reflection Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts ' This sample code creates a Web Parts control that acts as a consumer of row data. Namespace MyCustomWebPart Public NotInheritable Class RowConsumerWebPart Inherits WebPart Private _provider As IWebPartRow Private _tableData As ICollection Private Sub GetRowData(ByVal rowData As Object) _tableData = CType(rowData, ICollection) End Sub 'GetRowData Protected Overrides Sub OnPreRender(ByVal e As EventArgs) If Not (_provider Is Nothing) Then ' _provider.GetRowData(AddressOf (New RowCallback(GetRowData))) _provider.GetRowData(AddressOf GetRowData) ' _provider.GetRowData(New RowCallback(AddressOf GetRowData)) End If End Sub 'OnPreRender Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter) If Not (_provider Is Nothing) Then Dim props As PropertyDescriptorCollection = _provider.Schema Dim count As Integer = 0 If Not (props Is Nothing) AndAlso props.Count > 0 AndAlso Not (_tableData Is Nothing) Then Dim prop As PropertyDescriptor For Each prop In props Dim o As DataRow For Each o In _tableData writer.Write(prop.DisplayName & ": " & o(count)) writer.WriteBreak() writer.WriteLine() count = count + 1 Next o Next prop Else writer.Write("No data") End If Else writer.Write("Not connected") End If End Sub 'RenderContents <ConnectionConsumer("Row")> _ Public Sub SetConnectionInterface(ByVal provider As IWebPartRow) _provider = provider End Sub 'SetConnectionInterface '}
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Reflection; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; // This sample code creates a Web Parts control that acts as a consumer of row data. namespace My { public sealed class RowConsumerWebPart : WebPart { private IWebPartRow _provider; private ICollection _tableData; private void GetRowData(object rowData) { _tableData = (ICollection)rowData; } protected override void OnPreRender(EventArgs e) { if (_provider != null) { _provider.GetRowData(new RowCallback(GetRowData)); } } protected override void RenderContents(HtmlTextWriter writer) { if (_provider != null) { PropertyDescriptorCollection props = _provider.Schema; int count = 0; if (props != null && props.Count > 0 && _tableData != null) { foreach (PropertyDescriptor prop in props) { foreach (DataRow o in _tableData) { writer.Write(prop.DisplayName + ": " + o[count]); writer.WriteBreak(); writer.WriteLine(); count = count + 1; } } } else { writer.Write("No data"); } } else { writer.Write("Not connected"); } } [ConnectionConsumer("Row")] public void SetConnectionInterface(IWebPartRow provider) { _provider = provider; } } } //}
最後の例は、2 つのコントロールが含まれた ASP.NET ページを示します。
<%@ page language="VB" %> <%@ Register TagPrefix=my Namespace=MyCustomWebPart %> <html> <head runat="server"> <title>IRow Test Page</title> </head> <body> <form id="form1" runat="server"> <div> <!-- A static or dynamic connection is required to link two Web Parts controls. ---> <asp:webpartmanager ID="WebPartManager1" runat="server"> <staticconnections> <asp:webpartconnection ID=wp1 ProviderID=provider1 ConsumerID=consumer1 > </asp:webpartconnection> </staticconnections> </asp:webpartmanager> <asp:webpartzone ID="WebPartZone1" runat="server"> <ZoneTemplate> <my:RowProviderWebPart ID=provider1 runat=server Title="Row Provider Control" /> <my:RowConsumerWebPart ID=consumer1 runat=server Title="Row Consumer Control" /> </ZoneTemplate> </asp:webpartzone> </div> </form> </body> </html>
<%@ page language="C#" %> <%@ register TagPrefix="my" Namespace="My" %> <html> <head runat="server"> <title>IRow Test Page</title> </head> <body> <form id="form1" runat="server"> <div> <!-- A static or dynamic connection is required to link two Web Parts controls. ---> <asp:webpartmanager ID="WebPartManager1" runat="server"> <staticconnections> <asp:webpartconnection ID=wp1 ProviderID=provider1 ConsumerID=consumer1 > </asp:webpartconnection> </staticconnections> </asp:webpartmanager> <asp:webpartzone ID="WebPartZone1" runat="server"> <ZoneTemplate> <!-- The following two lines specify the two connected controls. ---> <my:RowProviderWebPart ID=provider1 runat=server Title="Row Provider Control" /> <my:RowConsumerWebPart ID=consumer1 runat=server Title="Row Consumer Control" /> </ZoneTemplate> </asp:webpartzone> </div> </form> </body> </html>


System.Attribute
System.Web.UI.WebControls.WebParts.ConnectionConsumerAttribute


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ConnectionConsumerAttribute メンバ
System.Web.UI.WebControls.WebParts 名前空間
WebPartConnection
ConnectionPoint
ConsumerConnectionPoint
ConnectionProviderAttribute
その他の技術情報
ASP.NET Web パーツ ページ
Web パーツ ページの保護
Web パーツ接続の概要
Weblioに収録されているすべての辞書からConnectionConsumerAttribute クラスを検索する場合は、下記のリンクをクリックしてください。

- ConnectionConsumerAttribute クラスのページへのリンク