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

Public Function CanConnectWebParts ( _ provider As WebPart, _ providerConnectionPoint As ProviderConnectionPoint, _ consumer As WebPart, _ consumerConnectionPoint As ConsumerConnectionPoint _ ) As Boolean
Dim instance As WebPartManager Dim provider As WebPart Dim providerConnectionPoint As ProviderConnectionPoint Dim consumer As WebPart Dim consumerConnectionPoint As ConsumerConnectionPoint Dim returnValue As Boolean returnValue = instance.CanConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint)
public bool CanConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint )
public: bool CanConnectWebParts ( WebPart^ provider, ProviderConnectionPoint^ providerConnectionPoint, WebPart^ consumer, ConsumerConnectionPoint^ consumerConnectionPoint )
public boolean CanConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint )
public function CanConnectWebParts ( provider : WebPart, providerConnectionPoint : ProviderConnectionPoint, consumer : WebPart, consumerConnectionPoint : ConsumerConnectionPoint ) : boolean
- providerConnectionPoint
provider が接続に関与できるようにする ConnectionPoint。
provider と consumer を接続できるかどうかを示すブール値。

CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) メソッドは、両方のコントロールが互換性のあるコネクション ポイント型を持っているため WebPartTransformer オブジェクトが不要な場合に、provider と consumer の接続に使用します。ConnectWebParts を呼び出してプログラムで接続を作成する前に、このメソッドを使用して 2 つのコントロールが接続できることを確認できます。
このオーバーロードは、トランスフォーマが不要になる点を除けば、CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint,WebPartTransformer) オーバーロードと同じ実装を使用します。

CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) メソッドを使用する方法を次のコード例に示します。
-
接続できる 2 つのカスタム WebPart コントロール、1 つの <asp:webpartmanager> 要素、および CanConnectWebParts メソッドを使用して接続を作成するいくつかのイベント処理コードを含む Web ページ。
-
2 つのカスタム WebPart コントロールおよび 1 つのカスタム インターフェイスを格納しているソース コード ファイル。
コード例の最初の部分は、表示モードを変更するユーザー コントロールです。このユーザー コントロールのソース コードは、WebPartManager クラスの概要の「例」から取得できます。表示モードの詳細およびユーザー コントロールの動作方法の詳細については、「チュートリアル : Web パーツ ページでの表示モードの変更」を参照してください。
Web ページの宣言マークアップには、ユーザー コントロールとカスタム コントロール両方の Register ディレクティブが含まれています。<asp:webpartmanager> 要素、カスタム コントロールを格納する <asp:webpartzone> 要素、および <asp:connectionszone> 要素があります。Page_Load メソッドで、コードは接続を作成できるかどうかをチェックし、作成できる場合は、プロバイダ、コンシューマ、およびそのそれぞれのコネクション ポイントを定義し、新しい接続を StaticConnections プロパティで参照される静的接続のセットに追加します。
<%@ 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 Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) ' Define provider, consumer, and connection points. Dim provider As WebPart = mgr.WebParts("zip1") Dim provConnPoint As ProviderConnectionPoint = _ mgr.GetProviderConnectionPoints(provider)("ZipCodeProvider") Dim consumer As WebPart = mgr.WebParts("weather1") Dim consConnPoint As ConsumerConnectionPoint = _ mgr.GetConsumerConnectionPoints(consumer)("ZipCodeConsumer") ' Check whether the connection already exists. If mgr.CanConnectWebParts(provider, provConnPoint, _ consumer, consConnPoint) Then ' Create a new static connection. Dim conn As New WebPartConnection() conn.ID = "staticConn1" conn.ConsumerID = "weather1" conn.ConsumerConnectionPointID = "ZipCodeConsumer" conn.ProviderID = "zip1" conn.ProviderConnectionPointID = "ZipCodeProvider" mgr.StaticConnections.Add(conn) End If End Sub </script> <html > <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <!-- Reference the WebPartManager control. --> <asp:WebPartManager ID="mgr" runat="server" /> <div> <uc1:DisplayModeMenuVB ID="displaymode1" runat="server" /> <!-- Reference consumer and provider controls in a zone. --> <asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <aspSample:ZipCodeWebPart ID="zip1" runat="server" Title="Zip Code Control"/> <aspSample:WeatherWebPart ID="weather1" runat="server" Title="Weather Control" /> </ZoneTemplate> </asp:WebPartZone> <hr /> <!-- Add a ConnectionsZone so users can connect controls. --> <asp:ConnectionsZone ID="ConnectionsZone1" runat="server" /> </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 Page_Load(object sender, EventArgs e) { // Define provider, consumer, and connection points. WebPart provider = mgr.WebParts["zip1"]; ProviderConnectionPoint provConnPoint = mgr.GetProviderConnectionPoints(provider)["ZipCodeProvider"]; WebPart consumer = mgr.WebParts["weather1"]; ConsumerConnectionPoint consConnPoint = mgr.GetConsumerConnectionPoints(consumer)["ZipCodeConsumer"]; // Check whether the connection already exists. if (mgr.CanConnectWebParts(provider, provConnPoint, consumer, consConnPoint)) { // Create a new static connection. WebPartConnection conn = new WebPartConnection(); conn.ID = "staticConn1"; conn.ConsumerID = "weather1"; conn.ConsumerConnectionPointID = "ZipCodeConsumer"; conn.ProviderID = "zip1"; conn.ProviderConnectionPointID = "ZipCodeProvider"; mgr.StaticConnections.Add(conn); } } </script> <html > <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <!-- Reference the WebPartManager control. --> <asp:WebPartManager ID="mgr" runat="server" /> <div> <uc1:DisplayModeMenuCS ID="displaymode1" runat="server" /> <!-- Reference consumer and provider controls in a zone. --> <asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <aspSample:ZipCodeWebPart ID="zip1" runat="server" Title="Zip Code Control"/> <aspSample:WeatherWebPart ID="weather1" runat="server" Title="Weather Control" /> </ZoneTemplate> </asp:WebPartZone> <hr /> <!-- Add a ConnectionsZone so users can connect controls. --> <asp:ConnectionsZone ID="ConnectionsZone1" runat="server" /> </div> </form> </body> </html>
コード例の 3 番目の部分は、コントロールのソース コードです。ここには、1 つのインターフェイスと 2 つのカスタム WebPart コントロール (1 つがプロバイダとして動作し、もう 1 つがコンシューマとして動作) が含まれています。これらは互換性のあるコネクション ポイントを持っているため (これらの両方が IZipCode インターフェイスを認識)、接続の作成にトランスフォーマは必要ありません。コード例を実行するためには、このソース コードをコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みのアセンブリを Web サイトの Bin フォルダまたはグローバル アセンブリ キャッシュに配置できます。サイトの App_Code フォルダにソース コードを配置し、実行時に動的にコンパイルすることもできます。コンパイル方法を示すチュートリアルについては、「チュートリアル : カスタム サーバー コントロールの開発と使用」を参照してください。
Imports System Imports System.Web Imports System.Web.Security Imports System.Security.Permissions Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Namespace Samples.AspNet.VB.Controls <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Interface IZipCode Property ZipCode() As String End Interface <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class ZipCodeWebPart Inherits WebPart Implements IZipCode Private zipCodeText As String = String.Empty Private input As TextBox Private send As Button Public Sub New() End Sub ' Make the implemented property personalizable to save ' the Zip Code between browser sessions. <Personalizable()> _ Public Property ZipCode() As String _ Implements IZipCode.ZipCode Get Return zipCodeText End Get Set(ByVal value As String) zipCodeText = value End Set End Property ' This is the callback method that returns the provider. <ConnectionProvider("Zip Code", "ZipCodeProvider")> _ Public Function ProvideIZipCode() As IZipCode Return Me End Function Protected Overrides Sub CreateChildControls() Controls.Clear() input = New TextBox() Me.Controls.Add(input) send = New Button() send.Text = "Enter 5-digit Zip Code" AddHandler send.Click, AddressOf Me.submit_Click Me.Controls.Add(send) End Sub Private Sub submit_Click(ByVal sender As Object, _ ByVal e As EventArgs) If input.Text <> String.Empty Then zipCodeText = Page.Server.HtmlEncode(input.Text) input.Text = String.Empty End If End Sub End Class <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class WeatherWebPart Inherits WebPart Private _provider As IZipCode Private _zipSearch As String Private DisplayContent As Label ' This method is identified by the ConnectionConsumer ' attribute, and is the mechanism for connecting with ' the provider. <ConnectionConsumer("Zip Code", "ZipCodeConsumer")> _ Public Sub GetIZipCode(ByVal Provider As IZipCode) _provider = Provider End Sub Protected Overrides Sub OnPreRender(ByVal e As EventArgs) EnsureChildControls() If Not (Me._provider Is Nothing) Then _zipSearch = _provider.ZipCode.Trim() DisplayContent.Text = "My Zip Code is: " + _zipSearch End If End Sub 'OnPreRender Protected Overrides Sub CreateChildControls() Controls.Clear() DisplayContent = New Label() Me.Controls.Add(DisplayContent) End Sub End Class End Namespace
namespace Samples.AspNet.CS.Controls { using System; using System.Web; using System.Web.Security; using System.Security.Permissions; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public interface IZipCode { string ZipCode { get; set;} } [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ZipCodeWebPart : WebPart, IZipCode { string zipCodeText = String.Empty; TextBox input; Button send; public ZipCodeWebPart() { } // Make the implemented property personalizable to save // the Zip Code between browser sessions. [Personalizable()] public virtual string ZipCode { get { return zipCodeText; } set { zipCodeText = value; } } // This is the callback method that returns the provider. [ConnectionProvider("Zip Code", "ZipCodeProvider")] public IZipCode ProvideIZipCode() { return this; } protected override void CreateChildControls() { Controls.Clear(); input = new TextBox(); this.Controls.Add(input); send = new Button(); send.Text = "Enter 5-digit Zip Code"; send.Click += new EventHandler(this.submit_Click); this.Controls.Add(send); } private void submit_Click(object sender, EventArgs e) { if (input.Text != String.Empty) { zipCodeText = Page.Server.HtmlEncode(input.Text); input.Text = String.Empty; } } } [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class WeatherWebPart : WebPart { private IZipCode _provider; string _zipSearch; Label DisplayContent; // This method is identified by the ConnectionConsumer // attribute, and is the mechanism for connecting with // the provider. [ConnectionConsumer("Zip Code", "ZipCodeConsumer")] public void GetIZipCode(IZipCode Provider) { _provider = Provider; } protected override void OnPreRender(EventArgs e) { EnsureChildControls(); if (this._provider != null) { _zipSearch = _provider.ZipCode.Trim(); DisplayContent.Text = "My Zip Code is: " + _zipSearch; } } protected override void CreateChildControls() { Controls.Clear(); DisplayContent = new Label(); this.Controls.Add(DisplayContent); } } }
ブラウザに Web ページを読み込んだ後、[Display Mode] ドロップダウン リスト コントロールをクリックし、[接続] を選択してページを接続モードに切り替えます。接続モードは、<asp:connectionszone> 要素を使用して、コントロールの間に接続を作成できるようにします。接続モードで、[ZIP Code] コントロールのタイトル バーにある下向きの矢印をクリックしてその動詞メニューをアクティブにし、[接続] をクリックします。接続ユーザー インターフェイス (UI) が表示されたら、Page_Load メソッドに格納されているコードによって既に接続が作成されていることを確認します。

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 クラス
WebPartManager メンバ
System.Web.UI.WebControls.WebParts 名前空間
ConnectWebParts
その他の技術情報
ASP.NET Web パーツ ページ
ASP.NET Web パーツ ページ
WebPartManager.CanConnectWebParts メソッド (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)
アセンブリ: System.Web (system.web.dll 内)

Public Overridable Function CanConnectWebParts ( _ provider As WebPart, _ providerConnectionPoint As ProviderConnectionPoint, _ consumer As WebPart, _ consumerConnectionPoint As ConsumerConnectionPoint, _ transformer As WebPartTransformer _ ) As Boolean
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 Boolean returnValue = instance.CanConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint, transformer)
public virtual bool CanConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer )
public: virtual bool CanConnectWebParts ( WebPart^ provider, ProviderConnectionPoint^ providerConnectionPoint, WebPart^ consumer, ConsumerConnectionPoint^ consumerConnectionPoint, WebPartTransformer^ transformer )
public boolean CanConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer )
public function CanConnectWebParts ( provider : WebPart, providerConnectionPoint : ProviderConnectionPoint, consumer : WebPart, consumerConnectionPoint : ConsumerConnectionPoint, transformer : WebPartTransformer ) : boolean
戻り値
provider と consumer で接続を構成できるかどうかを示すブール値。

CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint,WebPartTransformer) メソッドは、両方のコントロールが互換性のないコネクション ポイント型を持っているため WebPartTransformer オブジェクトが必要な場合に、provider と consumer の接続に使用します。ConnectWebParts を呼び出してプログラムで接続を作成する前に、このメソッドを使用して 2 つのコントロールが接続できることを確認できます。
このオーバーロードは、トランスフォーマが必要になる点を除けば、CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) オーバーロード同じ実装を使用します。

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.CanConnectWebParts メソッド

名前 | 説明 |
---|---|
WebPartManager.CanConnectWebParts (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint) | コンシューマ コントロールとプロバイダ コントロールが互換性のあるインターフェイスを持ち、WebPartTransformer オブジェクトが不要な場合に、接続に関係する WebPart コントロールをチェックし、こうしたコントロールを接続できるかどうかを判断します。 |
WebPartManager.CanConnectWebParts (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer) | 接続に関係する WebPart コントロールをチェックして、こうしたコントロールが接続可能かどうかを判断し、WebPartTransformer オブジェクトを使用して互換性のないコンシューマとプロバイダの間に接続を作成します。 |

関連項目
WebPartManager クラスWebPartManager メンバ
System.Web.UI.WebControls.WebParts 名前空間
ConnectWebParts
その他の技術情報
ASP.NET Web パーツ ページASP.NET Web パーツ ページ