WebPartManager.ConnectWebParts メソッド (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)
アセンブリ: System.Web (system.web.dll 内)

Public Function ConnectWebParts ( _ provider As WebPart, _ providerConnectionPoint As ProviderConnectionPoint, _ consumer As WebPart, _ consumerConnectionPoint As ConsumerConnectionPoint _ ) As WebPartConnection
Dim instance As WebPartManager Dim provider As WebPart Dim providerConnectionPoint As ProviderConnectionPoint Dim consumer As WebPart Dim consumerConnectionPoint As ConsumerConnectionPoint Dim returnValue As WebPartConnection returnValue = instance.ConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint)
public WebPartConnection ConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint )
public: WebPartConnection^ ConnectWebParts ( WebPart^ provider, ProviderConnectionPoint^ providerConnectionPoint, WebPart^ consumer, ConsumerConnectionPoint^ consumerConnectionPoint )
public WebPartConnection ConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint )
public function ConnectWebParts ( provider : WebPart, providerConnectionPoint : ProviderConnectionPoint, consumer : WebPart, consumerConnectionPoint : ConsumerConnectionPoint ) : WebPartConnection
- providerConnectionPoint
接続のコールバック メソッドとして機能するメソッド。Web パーツ コントロール セットに実装するときに、provider のパブリック メソッドを ConnectionProvider メタデータ属性でマークします。
- consumerConnectionPoint
providerConnectionPoint に接続し、接続のデータを受け取るメソッド。Web パーツ コントロール セットに実装するときに、consumer のパブリック メソッドを ConnectionConsumer メタデータ属性でマークします。
接続に必要なプロバイダとコンシューマに関するさまざまな情報が格納された WebPartConnection。


ConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) オーバーロードは、WebPartTransformer オブジェクトを使用しなくても接続できるだけの十分な互換性がコントロールのコネクション ポイントにある場合に、それらを接続するために使用します。このメソッドのオーバーロードを呼び出すと、それはメソッドの他のオーバーロードに呼び出しを渡し、WebPartTransformer オブジェクトを必要とするパラメータに対して null 参照 (Visual Basic では Nothing) を渡します。
プログラムで 2 つのコントロールを接続しようとする場合は、条件確認で CanConnectWebParts メソッドを使用して、コントロールを直接接続可能かどうかを判断できます。

ConnectWebParts メソッドを使用して、プログラムで接続を作成する方法のコード例を次に示します。例の実行に必要なコード全体については、WebPartManager クラスの概要で「例」を参照してください。その例の、ページ上の表示モードを変更できるユーザー コントロールのソース コードと、2 つのカスタム WebPart コントロールのソース コードが必要です。
この後に、2 つのコントロールをホストする Web ページのコードが続きます。このページは、先頭で Register ディレクティブを使用して、ユーザー コントロールとカスタム コントロールを宣言します。次に、<asp:webpartzone> 要素内の宣言でカスタム コントロールを参照します。Button1_Click メソッドを処理するコードで、ConnectWebParts メソッドを使用してコントロールの間に接続を作成します。
<%@ Page Language="vb" %> <%@ Register TagPrefix="uc1" TagName="DisplayModeMenuVB" Src="~/displaymodemenuvb.ascx" %> <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="ConnectionSampleVB"%> <script runat="server"> Protected Sub Button1_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Dim provPoint As ProviderConnectionPoint = _ mgr.GetProviderConnectionPoints(zip1)("ZipCodeProvider") Dim connPoint As ConsumerConnectionPoint = _ mgr.GetConsumerConnectionPoints(weather1)("ZipCodeConsumer") mgr.ConnectWebParts(zip1, provPoint, weather1, connPoint) End Sub Protected Sub mgr_DisplayModeChanged (ByVal sender as Object, _ ByVal e as WebPartDisplayModeEventArgs) If mgr.DisplayMode is WebPartManager.ConnectDisplayMode Then Button1.Visible = True Else Button1.Visible = False End If End Sub </script> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:WebPartManager ID="mgr" runat="server" OnDisplayModeChanged="mgr_DisplayModeChanged"> </asp:WebPartManager> <uc1:DisplayModeMenuVB ID="menu1" runat="server" /> <asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <aspSample:ZipCodeWebPart ID="zip1" runat="server" Title="Zip Code Provider" /> <aspSample:WeatherWebPart ID="weather1" runat="server" Title="Zip Code Consumer" /> </ZoneTemplate> </asp:WebPartZone> <asp:ConnectionsZone ID="ConnectionsZone1" runat="server"> </asp:ConnectionsZone> <asp:Button ID="Button1" runat="server" Text="Connect WebPart Controls" OnClick="Button1_Click" Visible="false" /> </div> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="~/displaymodemenucs.ascx" %> <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="ConnectionSampleCS"%> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { ProviderConnectionPoint provPoint = mgr.GetProviderConnectionPoints(zip1)["ZipCodeProvider"]; ConsumerConnectionPoint connPoint = mgr.GetConsumerConnectionPoints(weather1)["ZipCodeConsumer"]; WebPartConnection conn1 = mgr.ConnectWebParts(zip1, provPoint, weather1, connPoint); } protected void mgr_DisplayModeChanged(object sender, WebPartDisplayModeEventArgs e) { if (mgr.DisplayMode == WebPartManager.ConnectDisplayMode) Button1.Visible = true; else Button1.Visible = false; } </script> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:WebPartManager ID="mgr" runat="server" OnDisplayModeChanged="mgr_DisplayModeChanged"> </asp:WebPartManager> <uc1:DisplayModeMenuCS ID="menu1" runat="server" /> <asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <aspSample:ZipCodeWebPart ID="zip1" runat="server" Title="Zip Code Provider" /> <aspSample:WeatherWebPart ID="weather1" runat="server" Title="Zip Code Consumer" /> </ZoneTemplate> </asp:WebPartZone> <asp:ConnectionsZone ID="ConnectionsZone1" runat="server"> </asp:ConnectionsZone> <asp:Button ID="Button1" runat="server" Text="Connect WebPart Controls" OnClick="Button1_Click" Visible="false" /> </div> </form> </body> </html>
ブラウザにページを読み込んだ後、[Connect WebPart Controls] をクリックして接続を構成します。次に、テキスト ボックスに何らかのデータを入力し、[Enter 5-digit ZIP Code] をクリックして、コントロールが接続されていること、および最初のコントロールに入力したデータが 2 番目のコントロールで更新されることを示します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebPartManager.ConnectWebParts メソッド (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)
アセンブリ: System.Web (system.web.dll 内)

Public Overridable Function ConnectWebParts ( _ provider As WebPart, _ providerConnectionPoint As ProviderConnectionPoint, _ consumer As WebPart, _ consumerConnectionPoint As ConsumerConnectionPoint, _ transformer As WebPartTransformer _ ) As WebPartConnection
Dim instance As WebPartManager Dim provider As WebPart Dim providerConnectionPoint As ProviderConnectionPoint Dim consumer As WebPart Dim consumerConnectionPoint As ConsumerConnectionPoint Dim transformer As WebPartTransformer Dim returnValue As WebPartConnection returnValue = instance.ConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint, transformer)
public virtual WebPartConnection ConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer )
public: virtual WebPartConnection^ ConnectWebParts ( WebPart^ provider, ProviderConnectionPoint^ providerConnectionPoint, WebPart^ consumer, ConsumerConnectionPoint^ consumerConnectionPoint, WebPartTransformer^ transformer )
public WebPartConnection ConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer )
public function ConnectWebParts ( provider : WebPart, providerConnectionPoint : ProviderConnectionPoint, consumer : WebPart, consumerConnectionPoint : ConsumerConnectionPoint, transformer : WebPartTransformer ) : WebPartConnection
- consumerConnectionPoint
ConnectionConsumer メタデータ属性でマークされ、providerConnectionPoint と接続して接続のデータを受け取る、consumer のパブリック メソッド。
接続に必要なプロバイダ、コンシューマ、およびトランスフォーマに関する情報が格納された WebPartConnection。

ConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint,WebPartTransformer) オーバーロードは、コントロールのコネクション ポイントに互換性がない場合に、こうしたポイントを接続するために使用します。consumer が、provider のコネクション ポイントと異なるインターフェイスを実装すると、互換性が失われます。トランスフォーマは、consumer が認識可能な型にデータを変換します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebPartManager.ConnectWebParts メソッド

名前 | 説明 |
---|---|
WebPartManager.ConnectWebParts (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint) | コントロールへの参照とその指定された ConnectionPoint オブジェクトだけを使用して、2 つの WebPart コントロールまたは GenericWebPart コントロールの間に接続を作成します。 |
WebPartManager.ConnectWebParts (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer) | コントロールへの参照、指定された ConnectionPoint オブジェクト、および WebPartTransformer オブジェクトを使用して、2 つの WebPart コントロールまたは GenericWebPart コントロール間の接続を作成します。 |

関連項目
WebPartManager クラスWebPartManager メンバ
System.Web.UI.WebControls.WebParts 名前空間
GetConsumerConnectionPoints
GetProviderConnectionPoints
Connections
CanConnectWebParts