WebPartManager.ConnectWebParts メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
WebPart ゾーンに存在する 2 つのWebPartZoneBase コントロール (または接続を形成できる他のサーバー コントロール) 間の接続を作成します。
オーバーロード
| 名前 | 説明 |
|---|---|
| ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint) |
コントロールとその指定したWebPart オブジェクトへの参照のみを使用して、2 つのGenericWebPartまたはConnectionPoint コントロール間の接続を作成します。 |
| ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer) |
コントロール、指定したWebPart オブジェクト、およびGenericWebPart オブジェクトへの参照を使用して、2 つのConnectionPointまたはWebPartTransformer コントロール間の接続を作成します。 |
注釈
ConnectWebParts メソッドは、接続可能な 2 つのWebPart コントロール間の接続を形成します。 このメソッドを呼び出して接続を作成する前に、条件付きチェックで CanConnectWebParts メソッドを呼び出して、コントロールが接続を形成するための要件を満たしていることを確認することもできます。
Note
また、 WebPart コントロールではない 2 つのサーバー コントロール間に接続を作成することもできます。 一般に、2 つのコントロールは、必要なメンバーを追加できるように、カスタム サーバー コントロール (たとえば、WebControl または既存の ASP.NET サーバー コントロールから継承するコントロール) である必要があります。 コントロールは、以下に示す要件を満たす必要もあります。
2 つのコントロール間の任意の種類の接続シナリオは、接続できるようにするために次の要件を満たす必要があります。
各コントロールは、 WebPartZoneBase ゾーンに存在します (同じゾーンである必要はありません)。
Web パーツ コントロール セットに実装されているように、接続内のプロバイダー コントロールは、プロバイダーへのコールバックとして機能するパブリック メソッドとしてインターフェイスを実装し、プロバイダー接続ポイントとして識別する
ConnectionProviderメタデータ属性をメソッドに持ちます。 プロバイダーの接続ポイントを取得する GetProviderConnectionPoints メソッドは仮想であるため、派生 WebPartManager コントロールは必ずしも同じメタデータ属性を使用する必要はありません。Web パーツ コントロール セットに実装されているように、接続内のコンシューマー コントロールには、プロバイダーのコールバック メソッドで公開されているインターフェイスへの参照を取得できる特殊なメソッドもあります。コンシューマーには、コンシューマー接続ポイントとして識別する
ConnectionConsumerメタデータ属性がメソッドに含まれています。 コンシューマー接続ポイントを取得する GetConsumerConnectionPoints メソッドは仮想であるため、派生 WebPartManager コントロールは必ずしも同じメタデータ属性を使用する必要はありません。コールバック メソッドは、コンシューマーがプロバイダーのコールバック メソッドで提供されるインターフェイスの型を使用できる (つまり、コンシューマーとプロバイダーが直接データを共有できる) か、開発者が WebPartTransformer オブジェクトを使用してプロバイダーからデータをコンシューマーが使用できる形式に変換する必要があります。
Important
トランスフォーマーが不要な場合は、 ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint) メソッドのオーバーロードを使用します。 トランスフォーマーが必要な場合は、 ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer) メソッドのオーバーロードを使用します。
ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)
コントロールとその指定したWebPart オブジェクトへの参照のみを使用して、2 つのGenericWebPartまたはConnectionPoint コントロール間の接続を作成します。
public:
System::Web::UI::WebControls::WebParts::WebPartConnection ^ ConnectWebParts(System::Web::UI::WebControls::WebParts::WebPart ^ provider, System::Web::UI::WebControls::WebParts::ProviderConnectionPoint ^ providerConnectionPoint, System::Web::UI::WebControls::WebParts::WebPart ^ consumer, System::Web::UI::WebControls::WebParts::ConsumerConnectionPoint ^ consumerConnectionPoint);
public System.Web.UI.WebControls.WebParts.WebPartConnection ConnectWebParts(System.Web.UI.WebControls.WebParts.WebPart provider, System.Web.UI.WebControls.WebParts.ProviderConnectionPoint providerConnectionPoint, System.Web.UI.WebControls.WebParts.WebPart consumer, System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint consumerConnectionPoint);
member this.ConnectWebParts : System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ProviderConnectionPoint * System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint -> System.Web.UI.WebControls.WebParts.WebPartConnection
Public Function ConnectWebParts (provider As WebPart, providerConnectionPoint As ProviderConnectionPoint, consumer As WebPart, consumerConnectionPoint As ConsumerConnectionPoint) As WebPartConnection
パラメーター
- providerConnectionPoint
- ProviderConnectionPoint
接続のコールバック メソッドとして機能するメソッド。 Web パーツ コントロール セットに実装されているように、これは、providerメタデータ属性でマークされているConnectionProviderのパブリック メソッドです。
- consumerConnectionPoint
- ConsumerConnectionPoint
providerConnectionPointに接続して接続のデータを受信するメソッド。 Web パーツ コントロール セットに実装されているように、これは、consumerメタデータ属性でマークされているConnectionConsumerのパブリック メソッドです。
返品
接続に必要なプロバイダーとコンシューマーに関するさまざまな情報を含む WebPartConnection 。
例外
WebPartManager コントロールの動的コレクションのコレクションは読み取り専用です。
例
次のコード例では、このメソッドを使用してプログラムで接続を作成する方法を示します。 この例を実行するために必要な完全なコードについては、 WebPartManager クラスの概要の「例」セクションを参照してください。 この例では、ページの表示モードを変更できるユーザー コントロールのソース コードと、2 つのカスタム WebPart コントロールのソース コードが必要になります。
2 つのコントロールをホストする Web ページのコードは次のとおりです。 ページでは、上部 Register ディレクティブを使用して、ユーザー コントロールとカスタム コントロールを宣言します。 カスタム コントロールは、 <asp:webpartzone> 要素内で宣言によって参照されます。
Button1_Click メソッドを処理するコードは、ConnectWebParts メソッドを使用してコントロール間の接続を作成します。
<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc1"
TagName="DisplayModeMenuCS"
Src="~/displaymodemenucs.ascx" %>
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.CS.Controls"
Assembly="ConnectionSampleCS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ Page Language="vb" %>
<%@ Register TagPrefix="uc1"
TagName="DisplayModeMenuVB"
Src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.VB.Controls"
Assembly="ConnectionSampleVB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<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>
ブラウザーでページを読み込んだ後、[ WebPart コントロールの接続 ] ボタンをクリックして接続を形成します。 その後、テキスト ボックスにデータを入力し、[ 5 桁の郵便番号の入力 ] ボタンをクリックして、コントロールが接続されていること、および最初のコントロールに入力されたデータが 2 番目のコントロールで更新されることを示します。
注釈
このオーバーロードは、接続ポイントに十分な互換性があり、 WebPartTransformer オブジェクトを使用せずに接続できる場合に、コントロールを接続するために使用されます。 メソッドのこのオーバーロードが呼び出されると、メソッドの他のオーバーロードされたバージョンへの呼び出しを渡し、null オブジェクトを必要とするパラメーターのWebPartTransformerを渡します。
2 つのコントロールをプログラムで接続しようとすると、条件付きチェックで CanConnectWebParts メソッドを使用して、コントロールを直接接続できるかどうかを判断できます。
こちらもご覧ください
- GetConsumerConnectionPoints(WebPart)
- GetProviderConnectionPoints(WebPart)
- Connections
- ASP.NET Web パーツ コントロール
適用対象
ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)
コントロール、指定したWebPart オブジェクト、およびGenericWebPart オブジェクトへの参照を使用して、2 つのConnectionPointまたはWebPartTransformer コントロール間の接続を作成します。
public:
virtual System::Web::UI::WebControls::WebParts::WebPartConnection ^ ConnectWebParts(System::Web::UI::WebControls::WebParts::WebPart ^ provider, System::Web::UI::WebControls::WebParts::ProviderConnectionPoint ^ providerConnectionPoint, System::Web::UI::WebControls::WebParts::WebPart ^ consumer, System::Web::UI::WebControls::WebParts::ConsumerConnectionPoint ^ consumerConnectionPoint, System::Web::UI::WebControls::WebParts::WebPartTransformer ^ transformer);
public virtual System.Web.UI.WebControls.WebParts.WebPartConnection ConnectWebParts(System.Web.UI.WebControls.WebParts.WebPart provider, System.Web.UI.WebControls.WebParts.ProviderConnectionPoint providerConnectionPoint, System.Web.UI.WebControls.WebParts.WebPart consumer, System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint consumerConnectionPoint, System.Web.UI.WebControls.WebParts.WebPartTransformer transformer);
abstract member ConnectWebParts : System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ProviderConnectionPoint * System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint * System.Web.UI.WebControls.WebParts.WebPartTransformer -> System.Web.UI.WebControls.WebParts.WebPartConnection
override this.ConnectWebParts : System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ProviderConnectionPoint * System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint * System.Web.UI.WebControls.WebParts.WebPartTransformer -> System.Web.UI.WebControls.WebParts.WebPartConnection
Public Overridable Function ConnectWebParts (provider As WebPart, providerConnectionPoint As ProviderConnectionPoint, consumer As WebPart, consumerConnectionPoint As ConsumerConnectionPoint, transformer As WebPartTransformer) As WebPartConnection
パラメーター
- providerConnectionPoint
- ProviderConnectionPoint
providerのパブリック メソッド。ConnectionProvider メタデータ属性でマークされ、接続のコールバック メソッドとして機能します。
- consumerConnectionPoint
- ConsumerConnectionPoint
consumer メタデータ属性でマークされ、ConnectionConsumerに接続して接続のデータを受信する、providerConnectionPointのパブリック メソッド。
- transformer
- WebPartTransformer
データをWebPartTransformerから処理できる形式に変換することで、2 つのコントロール間の接続を可能にするproviderconsumer。
返品
接続に必要なプロバイダー、コンシューマー、およびトランスフォーマーに関する情報を含む WebPartConnection 。
例外
接続は既に PreRenderでアクティブ化されています。
注釈
このオーバーロードは、接続ポイントに互換性がない場合にコントロールを接続するために使用されます。 非互換性は、 consumer が接続ポイントとして provider とは異なるインターフェイスを実装する場合に発生します。 トランスフォーマーは、データを consumerで理解できる型に変換します。
こちらもご覧ください
- GetConsumerConnectionPoints(WebPart)
- GetProviderConnectionPoints(WebPart)
- Connections
- WebPartTransformer
- ASP.NET Web パーツ コントロール