ConsumerConnectionPointとは? わかりやすく解説

ConsumerConnectionPoint クラス

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

コンシューマとして動作するサーバー コントロールプロバイダとの接続構成できるようにする、コネクション ポイント オブジェクト定義します

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class ConsumerConnectionPoint
    Inherits ConnectionPoint
Dim instance As ConsumerConnectionPoint
public class ConsumerConnectionPoint : ConnectionPoint
public ref class ConsumerConnectionPoint :
 public ConnectionPoint
public class ConsumerConnectionPoint extends
 ConnectionPoint
public class ConsumerConnectionPoint extends
 ConnectionPoint
解説解説

2 つサーバー コントロール間におけるすべての Web パーツ接続で、それぞれのコントロール関連コネクション ポイント オブジェクト持っている必要があります関連コネクション ポイント オブジェクトでは、コントロールがもう一方コントロール接続でき、コントロールがその接続に関してプロバイダコンシューマのどちらとして指定されているかに応じてデータの提供側または使用側のいずれかとして動作できます通常ConnectionPoint オブジェクトには、一方コントロールがもう一方コントロール接続する方法および共有できるデータの種類に関する詳細格納されています。接続コンシューマとして動作するコントロール場合、そのコネクション ポイントConsumerConnectionPoint オブジェクトである必要がありますWeb パーツ接続コネクション ポイント詳細については、下の「参照セクション示されトピック参照してください

ConsumerConnectionPoint オブジェクト作成するには、次の手順実行する必要があります

  1. インターフェイス インスタンス参照するためにコンシューマ コントロール有効にます。WebPart またはその他のサーバー コントロール (WebPartZoneBase ゾーン追加される任意の種類サーバー コントロール使用できます) は、特定のインターフェイス インスタンスからのデータ使用できる必要があります。このコントロールインターフェイス実装する必要はありません。実装する必要があるのはプロバイダだけです。コンシューマプロバイダによって提供されるものとまったく同じインターフェイス型動作するか、同じでない場合は、WebPartTransformer オブジェクト使用してプロバイダインターフェイス型からコンシューマ認識できる型にデータ変換できます通常コンシューマ有効にするには、目的インターフェイス型への参照格納するプライベート フィールド宣言します

  2. コールバック メソッド識別します。コンシューマメソッドは、プロバイダとの接続確立するためのコールバック メソッドとして識別する必要があります。このメソッドは、プロバイダ実装しているインターフェイスインスタンス取得し、これをたとえば最初の手順で作成したプライベート フィールド割り当てますWeb パーツコンシューマコールバック メソッド識別するには、インターフェイス インスタンス受け取メソッドConnectionConsumer メタデータ属性 (ConnectionConsumerAttribute クラスで定義) を追加します。この属性追加すると、必須となるパラメータは、コンシューマ接続ポイント使用する表示名だけになりますID などの省略可能なパラメータ追加できます

  3. インターフェイス インスタンスからのデータ処理して出力しますデータ必要に応じて任意の内部処理実行し通常は、コンシューマ コントロールページデータ表示します。これを実行する一般的な方法として、コントロールの OnPreRender メソッドオーバーライドする方法挙げられます。

    メモメモ

    同期要求の間は、PreRender イベント発生しているときまたはこのイベント発生した直後に、コンシューマプロバイダからのデータ直接要求する必要があります非同期要求の間、表示中のいずれの時点においてもプロバイダコールバック メソッド呼び出されない場合開発者コンシューマデータ送信されなかったと推測できます

コントロールコンシューマとして動作するように装備されると、そのコントロール接続参加できます (プロバイダ コントロールも既に装備され利用可能になっていることが前提です)。Web ページマークアップ静的宣言接続作成するには、開発者は、<asp:webpartconnection> 要素使用できますコールバック メソッド識別するコンシューマ ソース コードConnectionConsumer 属性コネクション ポイントID指定する場合、その値をページ<asp:webpartconnection> 要素ConsumerConnectionPointID 属性割り当てる必要があります開発者コンシューマ接続ポイントID指定する理由は、コンシューマ コントロール複数コネクション ポイント定義されている場合があるためです。コンシューマ コントロールコンシューマ接続ポイントID指定されていない場合、DefaultID フィールドから取得した既定値使用して接続作成されるため、どのページConsumerConnectionPointID 属性にも値を割り当てる要はありません。

コード接続作成するには、 開発者は GetConsumerConnectionPoints メソッド呼び出してコンシューマ コントロール定義されConsumerConnectionPoint オブジェクトID またはインデックスと共にコンシューマ コントロールID渡し新しConsumerConnectionPoint オブジェクト作成する必要があります返されConsumerConnectionPoint オブジェクトすべてが、コンシューマ コントロールへの参照プロバイダ コントロールへの参照、および対応する ProviderConnectionPoint オブジェクトと共に ConnectWebParts メソッド渡され新しい WebPartConnection オブジェクト作成されます。

開発者接続確立する手順一部として宣言またはプログラムいずれか方法コンシューマ接続ポイント使用できますが、ユーザーユーザー インターフェイス (UI) を通じてコンシューマ接続ポイント操作することにより接続確立できます開発者Web ページで ConnectionsZone コントロール宣言すると、接続作成するランタイム UIユーザー表示されます。ユーザーがその Connect 動詞クリックし接続確立する際の開始ポイントとしてプロバイダ コントロール選択すると (コンシューマ選択することもできますが、接続違いはありません)、プロバイダからのデータ送信先として、利用可能コンシューマ接続ポイント表示名示されドロップダウン リスト コントロールUI表示されます。ユーザー接続確立するには、コンシューマ接続ポイント選択する必要があります

ConsumerConnectionPoint オブジェクト特定のコンシューマ コントロール直接関連付けられ、接続に関する詳細ConnectionPoint 基本クラスから継承したプロパティ格納します。たとえば、継承した InterfaceType プロパティに、コンシューマ接続ポイント使用するインターフェイスの型を保持します接続プロバイダコンシューマ両方がそのインターフェイス型認識する場合双方コントロール互換性があり、直接接続構成できますプロバイダコンシューマが同じインターフェイス型動作できない場合、これらに互換性がないため、WebPartTransformer オブジェクト使用してプロバイダ コネクション ポイントInterfaceType プロパティコンシューマ動作できる型に変換する必要がありますその他の重要な継承プロパティDisplayName プロパティあります。このプロパティは、接続作成時にユーザーコンシューマ接続ポイント選択する際の UI表示する表示名提供します表示名は、開発者コンシューマ コントロールコールバック メソッドConnectionConsumer 属性追加するときの必須パラメータです。継承されID プロパティは、コンシューマ複数コネクション ポイント持っている場合コンシューマ接続ポイント一意識別子提供するため、上に示した例と同様に役立ちますコンシューマは、複数ConsumerConnectionPoint オブジェクトを定義できます。この場合開発者メソッドConnectionConsumer 属性追加するときに、それぞれのコネクション ポイント識別するための ID 値を指定する必要があります。もう 1 つ重要な継承プロパティに、AllowsMultipleConnections プロパティあります。このプロパティは、コンシューマ接続ポイント同時に複数プロバイダ接続できるかどうか示します既定では、コンシューマ接続ポイント場合、このプロパティ値は falseなります (一方プロバイダ コネクション ポイント既定trueなります)。

ConsumerConnectionPoint クラスは、ConnectionPoint クラスから継承したメンバいくつかの独自のメソッド追加します。SetObject メソッドは、コンシューマ独自の定義済みコールバック メソッド呼び出しプロバイダからインターフェイス インスタンス取得します。SupportsConnection メソッドは、関連するコンシューマ コントロール現在の状態基づいてコネクション ポイント接続確立できるかどうかを示すブール値を返します

使用例使用例

宣言プログラム、または UI それぞれコンシューマ接続ポイント使用して接続作成する簡単な方法コード例次に示します

この例は、4 つ部分構成されます。

コード例最初部分は、Web ページ上の表示モードユーザー変更できるようにするユーザー コントロールです。ホストする Web ページ先頭近くにあるこのユーザー コントロール用の Register ディレクティブSrc 属性割り当てるファイル名付けて次のソース コード.ascx ファイル保存します表示モード詳細、およびこのコントロールソース コード説明については、「チュートリアル : Web パーツ ページでの表示モード変更」を参照してください

<%@ control language="vb" classname="DisplayModeMenuVB"%>
<script runat="server">
  ' Use a field to reference the current WebPartManager.
  Dim _manager As WebPartManager

  Sub Page_Init(ByVal sender As
 Object, ByVal e As EventArgs)
    AddHandler Page.InitComplete, AddressOf
 InitComplete
  End Sub

  Sub InitComplete(ByVal sender As
 Object, ByVal e As System.EventArgs)
    _manager = WebPartManager.GetCurrentWebPartManager(Page)
      
    Dim browseModeName As String
 = WebPartManager.BrowseDisplayMode.Name
      
    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In _manager.SupportedDisplayModes
      Dim modeName As String
 = mode.Name
      ' Make sure a mode is enabled before adding it.
      If mode.IsEnabled(_manager) Then
        Dim item As New
 ListItem(modeName, modeName)
        DisplayModeDropdown.Items.Add(item)
      End If
    Next mode
      
    ' If shared scope is allowed for this user, display the scope-switching
    ' UI and select the appropriate radio button for the current user
 scope.
    If _manager.Personalization.CanEnterSharedScope Then
      Panel2.Visible = True
      If _manager.Personalization.Scope = PersonalizationScope.User
 Then
        RadioButton1.Checked = True
      Else
        RadioButton2.Checked = True
      End If
    End If
   
  End Sub

  ' Change the page to the selected display mode.
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    
    Dim selectedMode As String
 = DisplayModeDropdown.SelectedValue   
    Dim mode As WebPartDisplayMode = _
      _manager.SupportedDisplayModes(selectedMode)
    If Not (mode Is Nothing)
 Then
      _manager.DisplayMode = mode
    End If

  End Sub
   
  ' Set the selected item equal to the current display mode.
  Sub Page_PreRender(ByVal sender As
 Object, ByVal e As EventArgs)
    Dim items As ListItemCollection = DisplayModeDropdown.Items
    Dim selectedIndex As Integer
 = _
      items.IndexOf(items.FindByText(_manager.DisplayMode.Name))
    DisplayModeDropdown.SelectedIndex = selectedIndex

  End Sub

  ' Reset all of a user's personalization data for the page.
  Protected Sub LinkButton1_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    
    _manager.Personalization.ResetPersonalizationState()
    
  End Sub

  ' If not in User personalization scope, toggle into it.
  Protected Sub RadioButton1_CheckedChanged(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    
    If _manager.Personalization.Scope = PersonalizationScope.Shared
 Then
      _manager.Personalization.ToggleScope()
    End If

  End Sub
   
  ' If not in Shared scope, and if user is allowed, toggle the scope.
  Protected Sub RadioButton2_CheckedChanged(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    
    If _manager.Personalization.CanEnterSharedScope AndAlso
 _
      _manager.Personalization.Scope = PersonalizationScope.User Then
      _manager.Personalization.ToggleScope()
    End If

  End Sub

</script>
<div>
  <asp:Panel ID="Panel1" runat="server"
 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server"
 
      Text="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
    <asp:DropDownList ID="DisplayModeDropdown"
 runat="server"  
      AutoPostBack="true" 
      Width="120"
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged"
 />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for
 the page."
      Font-Size="8" 
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server"
 
      GroupingText="Personalization Scope"
      Font-Bold="true"
      Font-Size="8" 
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server"
 
        Text="User" 
        AutoPostBack="true"
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged"
 />
      <asp:RadioButton ID="RadioButton2" runat="server"
 
        Text="Shared" 
        AutoPostBack="true"
        GroupName="Scope" 
        OnCheckedChanged="RadioButton2_CheckedChanged"
 />
    </asp:Panel>
  </asp:Panel>
</div>
<%@ control language="C#" classname="DisplayModeMenuCS"%>
<script runat="server">
  
 // Use a field to reference the current WebPartManager.
  WebPartManager _manager;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }  

  void InitComplete(object sender, System.EventArgs e)
  {
    _manager = WebPartManager.GetCurrentWebPartManager(Page);

    String browseModeName = WebPartManager.BrowseDisplayMode.Name;

    // Fill the dropdown with the names of supported display modes.
    foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
    {
      String modeName = mode.Name;
      // Make sure a mode is enabled before adding it.
      if (mode.IsEnabled(_manager))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }
    }

    // If shared scope is allowed for this user, display the scope-switching
    // UI and select the appropriate radio button for the current user
 scope.
    if (_manager.Personalization.CanEnterSharedScope)
    {
      Panel2.Visible = true;
      if (_manager.Personalization.Scope == PersonalizationScope.User)
        RadioButton1.Checked = true;
      else
        RadioButton2.Checked = true;
    }
    
  }
 
  // Change the page to the selected display mode.
  void DisplayModeDropdown_SelectedIndexChanged(object sender,
 EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;

    WebPartDisplayMode mode = _manager.SupportedDisplayModes[selectedMode];
    if (mode != null)
      _manager.DisplayMode = mode;
  }

  // Set the selected item equal to the current display mode.
  void Page_PreRender(object sender, EventArgs e)
  {
    ListItemCollection items = DisplayModeDropdown.Items;
    int selectedIndex = 
      items.IndexOf(items.FindByText(_manager.DisplayMode.Name));
    DisplayModeDropdown.SelectedIndex = selectedIndex;
  }

  // Reset all of a user's personalization data for the page.
  protected void LinkButton1_Click(object sender,
 EventArgs e)
  {
    _manager.Personalization.ResetPersonalizationState();
  }

  // If not in User personalization scope, toggle into it.
  protected void RadioButton1_CheckedChanged(object
 sender, EventArgs e)
  {
    if (_manager.Personalization.Scope == PersonalizationScope.Shared)
      _manager.Personalization.ToggleScope();
  }

  // If not in Shared scope, and if user is allowed, toggle the scope.
  protected void RadioButton2_CheckedChanged(object
 sender, EventArgs e)
  {
    if (_manager.Personalization.CanEnterSharedScope &&
 
        _manager.Personalization.Scope == PersonalizationScope.User)
      _manager.Personalization.ToggleScope();
  }
</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"
  
      AutoPostBack="true" 
      Width="120"
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged"
 />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for
 the page."
      Font-Size="8" 
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Font-Bold="true"
      Font-Size="8" 
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        Text="User" 
        AutoPostBack="true"
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged"
 />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        Text="Shared" 
        AutoPostBack="true"
        GroupName="Scope" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />
    </asp:Panel>
  </asp:Panel>
</div>

コード例2 番目の部分は、インターフェイスコントロールソース コードです。ソース ファイルには、IZipCode という名前の簡単なインターフェイス含まれています。また、インターフェイス実装してプロバイダ コントロールとして動作するZipCodeWebPart という名前の WebPart クラス含まれています。もう一方WebPart クラスには WeatherWebPart という名前が付けられ接続コンシューマとして動作します。このクラスは、プロバイダ コントロールかIZipCode インターフェイスインスタンス取得するGetZipCode という名前のメソッド持ってます。このメソッドは、メタデータConnectionConsumer 属性で、コンシューマコネクション ポイント メソッドとしてマークされています。これは、コンシューマ コントロールコネクション ポイント メソッド識別するためのしくみです。

コード例実行するためには、このソース コードコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みアセンブリ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 Provider", "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 Consumer", "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 Provider", "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 Consumer", "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);
    }

  }
}

コード例3 番目の部分Web ページです。先頭近くには、接続構成するカスタム コントロール登録する Register ディレクティブ、およびユーザーページ表示モード変更できるユーザー コントロールあります接続は、ページ<staticconnections> 要素内で宣言して作成されます。これは、<asp:webpartconnection> 要素ConsumerConnectionPointID 属性接続作成する 1 つ方法示してます。プログラム接続作成することもできます作成するコードButton1_Click メソッド内に組み込みます。この場合ConsumerConnectionPoint オブジェクト作成し実際接続作成するメソッド渡します宣言またはプログラムいずれか接続作成する場合コネクション ポイントプロバイダコンシューマ両方に対して指定する必要がありますButton2_Click メソッドプロバイダコンシューマ両方ConnectionPoint オブジェクトアクセスし、そのプロパティ値の一部ページラベル書き込みます

<%@ Page Language="VB" %>
<%@ register tagprefix="uc1" 
    tagname="DisplayModeMenuVB"
    src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="Samples.AspNet.VB.Controls"
 %>
    
<!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")

    If mgr.CanConnectWebParts(zip1, provPoint, weather1, connPoint)
 Then
      mgr.ConnectWebParts(zip1, provPoint, weather1, connPoint)
    End If
    
  End Sub
  
  Protected Sub Button2_Click(ByVal
 sender As Object, _
    ByVal e As System.EventArgs)
    
    Dim conn As WebPartConnection = mgr.Connections(0)

    lblConn.Text = "<h2>Connection Point Details</h2>"
 & _
      "<h3>Provider Connection Point</h3>"
 & _
      "  Display name: " & conn.ProviderConnectionPoint.DisplayName
 & _
      "<br />" & _
      "  ID: " & conn.ProviderConnectionPoint.ID
 & _
      "<br />" & _
      "  Interface type: " & conn.ProviderConnectionPoint.InterfaceType.ToString()
 & _
      "<br />" & _
      "  Control type: " & conn.ProviderConnectionPoint.ControlType.ToString()
 & _
      "<br />" & _
      "  Allows multiple connections: " & _
        conn.ProviderConnectionPoint.AllowsMultipleConnections.ToString() & _
      "<br />" & _
      "  Enabled: " & conn.ProviderConnectionPoint.GetEnabled(zip1).ToString()
 & _
      "<hr />" & _
      "<h3>Consumer Connection Point</h3>"
 & _
      "  Display name: " & conn.ConsumerConnectionPoint.DisplayName
 & _
      "<br />" & _
      "  ID: " & conn.ConsumerConnectionPoint.ID
 & _
      "<br />" & _
      "  Interface type: " & conn.ConsumerConnectionPoint.InterfaceType.ToString()
 & _
      "<br />" & _
      "  Control type: " & conn.ConsumerConnectionPoint.ControlType.ToString()
 & _
      "<br />" & _
      "  Allows multiple connections: " & _
        conn.ConsumerConnectionPoint.AllowsMultipleConnections.ToString() & _
      "<br />" & _
      "  Enabled: " & conn.ConsumerConnectionPoint.GetEnabled(zip1).ToString()
          
  End Sub

  Protected Sub Page_Load(ByVal
 sender As Object, _
    ByVal e As System.EventArgs)
    lblConn.Text = String.Empty
  End Sub
  
</script>

<html  >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr" runat="server"
 >
        <StaticConnections>
          <asp:WebPartConnection ID="conn1"
            ConsumerConnectionPointID="ZipCodeConsumer"
            ConsumerID="weather1" 
            ProviderConnectionPointID="ZipCodeProvider"
 
            ProviderID="zip1" />
        </StaticConnections>      
      </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="Dynamic Connection" 
        OnClick="Button1_Click" />      
      <br />
      <asp:Button ID="Button2" runat="server"
 
        Text="Connection Point Details" 
        OnClick="Button2_Click" />
      <br />
      <asp:Label ID="lblConn" 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" %>
    
<!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"];
      
    if(mgr.CanConnectWebParts(zip1, provPoint, weather1, connPoint))
      mgr.ConnectWebParts(zip1, provPoint, weather1, connPoint);
  
  }  
  protected void Button2_Click(object sender,
 EventArgs e)
  {
    WebPartConnection conn = mgr.Connections[0];
    
    lblConn.Text = "<h2>Connection Point Details</h2>" + 
       "<h3>Provider Connection Point</h3>" + 
       "  Display name: " + conn.ProviderConnectionPoint.DisplayName +
 
       "<br />" + 
       "  ID: " + conn.ProviderConnectionPoint.ID + 
       "<br />" + 
       "  Interface type: " + 
        conn.ProviderConnectionPoint.InterfaceType.ToString() + 
       "<br />" + 
       "  Control type: " + conn.ProviderConnectionPoint.ControlType.ToString()
 + 
       "<br />" + 
       "  Allows multiple connections: " + 
          conn.ProviderConnectionPoint.AllowsMultipleConnections.ToString() + 
       "<br />" + 
       "  Enabled: " + conn.ProviderConnectionPoint.GetEnabled(zip1).ToString()
 + 
       "<hr />" + 
       "<h3>Consumer Connection Point</h3>" + 
       "  Display name: " + conn.ConsumerConnectionPoint.DisplayName +
 
       "<br />" + 
       "  ID: " + conn.ConsumerConnectionPoint.ID + 
       "<br />" + 
       "  Interface type: " + conn.ConsumerConnectionPoint.InterfaceType.ToString()
 + 
       "<br />" + 
       "  Control type: " + conn.ConsumerConnectionPoint.ControlType.ToString()
 + 
       "<br />" + 
       "  Allows multiple connections: " + 
          conn.ConsumerConnectionPoint.AllowsMultipleConnections.ToString() + 
       "<br />" + 
       "  Enabled: " + conn.ConsumerConnectionPoint.GetEnabled(zip1).ToString();
  }

  protected void Page_Load(object sender, EventArgs
 e)
  {
    lblConn.Text = String.Empty;
  }
</script>

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr" runat="server" >
        <StaticConnections>
          <asp:WebPartConnection ID="conn1"
            ConsumerConnectionPointID="ZipCodeConsumer"
            ConsumerID="weather1" 
            ProviderConnectionPointID="ZipCodeProvider" 
            ProviderID="zip1" />
        </StaticConnections>      
      </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="Dynamic Connection" 
        OnClick="Button1_Click" />      
      <br />
      <asp:Button ID="Button2" runat="server" 
        Text="Connection Point Details" 
        OnClick="Button2_Click" />
      <br />
      <asp:Label ID="lblConn" runat="server" />
    </div>
    </form>
</body>
</html>

ブラウザページ読み込んだ後、[Connection Point Details] ボタンクリックします。宣言によって接続確立されプロバイダ コネクション ポイントコンシューマ接続ポイントに関する情報表示されます。次に、[Display Mode] ドロップダウン コントロール使用してページ接続モード切り替えます。[ZIP Code Provider]WebPart コントロール (タイトル バー下向き矢印表示) の動詞メニューで、Connect 動詞クリックします。接続 UI表示されページ宣言され<asp:connectionszone> コントロールによって自動的に作成されます。これは、前に説明した宣言およびプログラムによる方法と共にUI使用して接続作成するもう 1 つ方法です。[切断] ボタンクリックし既存静的接続終了します。[コンシューマへの接続作成] リンクをクリックします。UI に、コンシューマ接続ポイント表示名示されたドロップダウン コントロール表示されます。ドロップダウン リストコネクション ポイント選択し、[接続] をクリックして接続確立します。次にもう一度 [切断] をクリックします。[Dynamic Connection] ボタンクリックしプログラム接続作成します。[Display Mode] コントロール使用してページブラウズ モード戻しますもう一度 [Connection Point Details] ボタンクリックしコンシューマ接続ポイント オブジェクトに関する詳細表示します

この例では、Web ページマークアップ宣言した静的接続ConsumerConnectionPoint オブジェクト使用するコード作成した接続、および接続 UI通じてユーザー作成した接続3 つの方法で、接続確立してコンシューマ接続ポイント使用する方法示しました

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.WebControls.WebParts.ConnectionPoint
    System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConsumerConnectionPoint メンバ
System.Web.UI.WebControls.WebParts 名前空間
WebPartConnection
ProviderConnectionPoint
その他の技術情報
ASP.NET Web パーツ ページ
Web パーツ接続概要

ConsumerConnectionPoint コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

ConsumerConnectionPoint クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    callbackMethod As MethodInfo, _
    interfaceType As Type, _
    controlType As Type, _
    displayName As String, _
    id As String, _
    allowsMultipleConnections As Boolean _
)
Dim callbackMethod As MethodInfo
Dim interfaceType As Type
Dim controlType As Type
Dim displayName As String
Dim id As String
Dim allowsMultipleConnections As Boolean

Dim instance As New ConsumerConnectionPoint(callbackMethod,
 interfaceType, controlType, displayName, id, allowsMultipleConnections)
public ConsumerConnectionPoint (
    MethodInfo callbackMethod,
    Type interfaceType,
    Type controlType,
    string displayName,
    string id,
    bool allowsMultipleConnections
)
public:
ConsumerConnectionPoint (
    MethodInfo^ callbackMethod, 
    Type^ interfaceType, 
    Type^ controlType, 
    String^ displayName, 
    String^ id, 
    bool allowsMultipleConnections
)
public ConsumerConnectionPoint (
    MethodInfo callbackMethod, 
    Type interfaceType, 
    Type controlType, 
    String displayName, 
    String id, 
    boolean allowsMultipleConnections
)
public function ConsumerConnectionPoint (
    callbackMethod : MethodInfo, 
    interfaceType : Type, 
    controlType : Type, 
    displayName : String, 
    id : String, 
    allowsMultipleConnections : boolean
)

パラメータ

callbackMethod

接続確立するためのインターフェイス インスタンスコンシューマ返すコンシューマ コントロールメソッド

interfaceType

コンシューマプロバイダから受け取インターフェイスType

controlType

コンシューマ接続ポイント関連付けられたコンシューマ コントロールType

displayName

接続ユーザー インターフェイス (UI) でユーザーに対して表示されるコンシューマ接続ポイント表示名

id

コンシューマ接続ポイント一意識別子

allowsMultipleConnections

コンシューマ接続ポイントが、プロバイダとの間で同時に複数接続を持つことができるかどうかを示すブール値。

例外例外
例外種類条件

ArgumentNullException

callbackMethodnull 参照 (Visual Basic では Nothing) です。

または

interfaceTypenull 参照 (Visual Basic では Nothing) です。

または

controlTypenull 参照 (Visual Basic では Nothing) です。

または

displayNamenull 参照 (Visual Basic では Nothing) または空の文字列 ("") です。

ArgumentException

controlType が、コンシューマ コントロール (またはそれから派生した有効なクラス) と同じ型ではありません。

解説解説
使用例使用例

ConsumerConnectionPoint クラス派生としてカスタム プロバイダ コネクション ポイント作成する方法次のコード例示します

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

コード例最初部分は、プロバイダコンシューマWebPart コントロールカスタム ConsumerConnectionPoint クラス指定されTableConsumerConnectionPointソースです。TableConsumerConnectionPoint クラスコンストラクタ基本コンストラクタ呼び出し、それに「パラメータセクション示した必須パラメータ渡しますまた、TableConsumer クラスでは、接続コールバック メソッドとして SetConnectionInterface メソッド指定しConnectionConsumer 属性パラメータとしてカスタム TableConsumerConnectionPoint宣言します。これは、カスタム コンシューマ接続ポイント作成し、それをコンシューマ コントロール関連付ける方法示してます。この例ではソース コード動的にコンパイルすることを想定しているため、Web アプリケーションの App_Code サブフォルダソース コード ファイル配置する必要があります

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
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 table data.
namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class TableProviderWebPart
 : WebPart, IWebPartTable
    {
        DataTable _table;

        public TableProviderWebPart()
        {
            _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);
        }

        public PropertyDescriptorCollection Schema
        {
            get
            {
                return TypeDescriptor.GetProperties(_table.DefaultView[0]);
            }
        }
        public void GetTableData(TableCallback
 callback)
        {
                callback(_table.Rows);
        }

        public bool ConnectionPointEnabled
        {
            get
            {
                object o = ViewState["ConnectionPointEnabled"];
                return (o != null) ? (bool)o
 : true;
            }
            set
            {
                ViewState["ConnectionPointEnabled"] = value;
            }
        }

        [ConnectionProvider("Table", typeof(TableProviderConnectionPoint),
 AllowsMultipleConnections = true)]
        public IWebPartTable GetConnectionInterface()
        {
            return new TableProviderWebPart();
        }

        public class TableProviderConnectionPoint
 : ProviderConnectionPoint
        {
            public TableProviderConnectionPoint(MethodInfo callbackMethod,
 Type interfaceType, Type controlType,
            string name, string id, bool
 allowsMultipleConnections) : base(
                callbackMethod, interfaceType, controlType,
                name, id, allowsMultipleConnections)
            {
            }
            public override bool GetEnabled(Control
 control)
            {
                return ((TableProviderWebPart)control).ConnectionPointEnabled;
            }
        }
    }
    
    // This code sample demonstrates a custom WebPart controls that
 acts as 
    // a consumer in a Web Parts connection.
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class TableConsumer : WebPart
  {
    private IWebPartTable _provider;
    private ICollection _tableData;

    private void GetTableData(object tableData)
    {
      _tableData = (ICollection)tableData;
    }

    protected override void OnPreRender(EventArgs
 e)
    {
      if (_provider != null)
      {
        _provider.GetTableData(new TableCallback(GetTableData));
      }
    }


    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("Table")]
    public void SetConnectionInterface(IWebPartTable
 provider)
    {
      _provider = provider;
    }

    public class TableConsumerConnectionPoint
 : ConsumerConnectionPoint
    {
      public TableConsumerConnectionPoint(MethodInfo callbackMethod,
 Type interfaceType, Type controlType,
      string name, string id, bool
 allowsMultipleConnections)
        : base(
        callbackMethod, interfaceType, controlType,
        name, id, allowsMultipleConnections)
      {
      }
    }
  }
}

コード例2 番目の部分は、静的Web パーツ接続カスタム コントロールホストする Web ページです。ページ先頭Register ディレクティブがあり、カスタム コントロールプレフィックス名前空間宣言します接続<asp:webpartconnection> 要素使用して宣言されプロバイダ コントロールコンシューマ コントロール<asp:webpartzone> 要素内に宣言されます。

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
    namespace="Samples.AspNet.CS.Controls" %>

<html>
<head runat="server">
    <title>IField Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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>
            <aspSample:TableProviderWebPart ID=provider1 runat=Server 
              title="Web Parts Table Provider Control" />
            <aspSample:TableConsumer ID=consumer1 runat=Server 
              title="Web Parts Table Consumer Control"/>
          </zoneTemplate>
        </asp:webpartzone>
    </div>
    </form>
</body>
</html>

ブラウザページ読み込みます。これらのコントロール間の接続は既に存在し接続ページ静的接続として宣言されているため、プロバイダからのデータコンシューマ表示されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConsumerConnectionPoint クラス
ConsumerConnectionPoint メンバ
System.Web.UI.WebControls.WebParts 名前空間
GetConsumerConnectionPoints
その他の技術情報
ASP.NET Web パーツ ページ

ConsumerConnectionPoint プロパティ


ConsumerConnectionPoint メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ConsumerConnectionPoint クラス
System.Web.UI.WebControls.WebParts 名前空間
WebPartConnection
ProviderConnectionPoint

その他の技術情報

ASP.NET Web パーツ ページ
Web パーツ接続概要

ConsumerConnectionPoint メンバ

コンシューマとして動作するサーバー コントロールプロバイダとの接続構成できるようにする、コネクション ポイント オブジェクト定義します

ConsumerConnectionPoint データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ConsumerConnectionPoint ConsumerConnectionPoint クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ConsumerConnectionPoint クラス
System.Web.UI.WebControls.WebParts 名前空間
WebPartConnection
ProviderConnectionPoint

その他の技術情報

ASP.NET Web パーツ ページ
Web パーツ接続概要



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

辞書ショートカット

すべての辞書の索引

「ConsumerConnectionPoint」の関連用語

ConsumerConnectionPointのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS