WebPartManager.CanConnectWebPartsとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > WebPartManager.CanConnectWebPartsの意味・解説 

WebPartManager.CanConnectWebParts メソッド (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

コンシューマ コントロールプロバイダ コントロール互換性のあるインターフェイス持ち、WebPartTransformer オブジェクト不要な場合に、接続関係する WebPart コントロールチェックしこうしたコントロール接続できるかどうか判断します

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: 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

パラメータ

provider

コントロール接続したときに、consumerデータ提供するコントロール

providerConnectionPoint

provider接続関与できるようにする ConnectionPoint

consumer

コントロール接続したときに、provider からデータ受け取コントロール

consumerConnectionPoint

consumer接続関与できるように、コールバック メソッドとして機能する ConnectionPoint

戻り値
providerconsumer接続できるかどうかを示すブール値。

解説解説

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

このオーバーロードは、トランスフォーマが不要になる点を除けば、CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint,WebPartTransformer) オーバーロードと同じ実装使用します

使用例使用例

CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) メソッド使用する方法次のコード例示します

コード例は、次の 4 つ部分から成ります

コード例最初部分は、表示モード変更するユーザー コントロールです。このユーザー コントロールソース コードは、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 メソッド格納されているコードによって既に接続作成されていることを確認します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebPartManager.CanConnectWebParts メソッド (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

接続関係する WebPart コントロールチェックしてこうしたコントロール接続可能かどうか判断しWebPartTransformer オブジェクト使用して互換性のないコンシューマプロバイダの間に接続作成します

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: 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データ提供するコントロール

providerConnectionPoint

provider接続関与できるように、コールバック メソッドとして機能する ConnectionPoint

consumer

コントロール接続したときに、provider からデータ受け取コントロール

consumerConnectionPoint

consumer接続関与できるように、コールバック メソッドとして機能する ConnectionPoint

transformer

互換性のない providerconsumer接続可能にする WebPartTransformer。

戻り値
providerconsumer接続構成できるかどうかを示すブール値。

解説解説

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

このオーバーロードは、トランスフォーマが必要になる点を除けば、CanConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) オーバーロード同じ実装使用します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebPartManager クラス
WebPartManager メンバ
System.Web.UI.WebControls.WebParts 名前空間

WebPartManager.CanConnectWebParts メソッド




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

「WebPartManager.CanConnectWebParts」の関連用語


WebPartManager.CanConnectWebPartsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebPartManager.CanConnectWebPartsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS