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

WebPartConnection クラス

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

2 つWebPart コントロール接続構成できるようにするオブジェクト提供します。このクラス継承できません。

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

Public NotInheritable Class
 WebPartConnection
Dim instance As WebPartConnection
public sealed class WebPartConnection
public ref class WebPartConnection sealed
public final class WebPartConnection
public final class WebPartConnection
解説解説

Web パーツ コントロール セットでは、接続は、データ共有できるようにする 2 つWebPart (または他のサーバーユーザー) コントロール間のリンクまたは関連付け表します。このデータ共有機能により、接続対象となるコントロールは、単独コントロール提供される機能上回る多く方法使用できます。たとえば、一方コントロール郵便番号データ提供し、もう一方コントロールがそのデータ読み込んで郵便番号基づいて地域気象情報提供すると、2 つコントロール機能接続され、より多く価値ユーザー提供されます。この例を拡張し郵便番号基づいて情報表示する別のコントロール (地域ニュースリンクするコントロールなど) も作成できます郵便番号データ処理できるこうしたコントロールすべてにおいて、郵便番号提供する単一コントロールデータ共有できますWeb パーツ アプリケーションエンド ユーザーは、ConnectionsZone コントロール提供される標準接続ユーザー インターフェイス (UI: User Interface) を使用するか、または開発者用意したカスタム UI使用して、これらの互換性のあるコントロール間の接続Web ブラウザから直接作成して管理できます

この WebPartConnection クラス概要は、接続作成するための基本的な内容について一般的な説明です。接続作成関係する特定のコンポーネントおよび要件詳細については、「Web パーツ接続概要」を参照するか、次に説明する参照クラスコード例参照してくださいWeb パーツ接続には次のようないくつかの基本的な要素あります

WebPartConnection クラスは、2 つWebPart コントロール間の接続に関する基本的な詳細カプセル化するオブジェクト定義します。このクラスは、特定の接続詳細に関連するほとんどすべてのプロパティ構成されます。いくつかのプロパティは、接続コンシューマ コントロール関係しますConsumer プロパティコンシューマ コントロール自体参照し、ConsumerID プロパティコンシューマID参照します。ConsumerConnectionPoint オブジェクトコンシューマコネクション ポイントに関する詳細格納しコンシューマの ConsumerConnectionPoint プロパティによって参照されます。ConsumerConnectionPointID プロパティは、ConsumerConnectionPoint オブジェクトID参照します。これらすべてのコンシューマ関連コネクションプロパティには、接続作成するための値を割り当てる必要があります

また、WebPartConnection クラス接続プロバイダ コントロール関連するいくつかのプロパティ持ち、これらはコンシューマプロパティ相当しますProvider プロパティプロバイダ コントロール自体参照し、ProviderID プロパティはその ID参照します。ProviderConnectionPoint プロパティProviderConnectionPoint オブジェクト参照し、ProviderConnectionPointID プロパティは、プロバイダコネクション ポイントID参照します。

いくつかのプロパティは、接続の状態に関係します。IsActive プロパティは、接続アクティブ (現在データ交換中) か、アクティブでない (接続されていてもアクティブデータ共有していない) かを示します。IsShared プロパティは、接続共有されている (ページすべてのユーザー利用可能) か、ユーザー固有の接続かを示し、IsStatic プロパティは、コントロール静的 (ページマークアップ宣言され永続的) か、動的 (プログラム作成され削除可能) かを示します

使用例使用例

2 つWebPart コントロール間に簡単な接続作成する方法コード例次に示します。この例では、宣言による方法 (Web ページマークアップ接続タグ配置する)、プログラムによる方法 (コード接続作成する)、および UI使用する方法 (ページ上に ConnectionsZone コントロール配置してユーザー接続確立できるようにする) の 3 種類の接続構成方法示します

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

コード例最初部分は、Web ページ上の表示モードユーザー変更できるようにするユーザー コントロールです。次のソース コード.ascx ファイル保存します。このファイルの名前は、ホストする Web ページ先頭近くにある、このユーザー コントロール用の Register ディレクティブSrc 属性割り当てられます。表示モード詳細、およびこのコントロールソース コード説明については、「チュートリアル : 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 クラス存在します。その ProvideIZipCode メソッドは、インターフェイス唯一のメンバ実装されたコールバック メソッドです。このメソッドは、単にインターフェイスインスタンス返すだけです。このメソッドメタデータConnectionProvider 属性マークされます。これは、メソッドプロバイダコネクション ポイントコールバック メソッドとして識別するしくみです。もう 1 つ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 ページです。先頭近くに、ユーザー コントロールカスタム WebPart コントロールRegister ディレクティブあります。この例はコントロール動的コンパイル前提にしているため、コントロールソース コードを App_Code サブフォルダ格納する必要がありますページRegister タグ任意のタグ プリフィックスコントロール名前空間のみを参照します。カスタム WebPart コントロール (プロバイダコンシューマ) は、<zonetemplate> 要素内部の、Web ページ<asp:webpartzone> 要素内に宣言します

このページは、次の 3 つの方法カスタム コントロール間の接続構成します最初方法では、宣言使用しますページマークアップで、<StaticConnections> 要素宣言しその内部に、接続コンシューマプロバイダさまざまな詳細属性として指定され<asp:WebPartConnections> 要素宣言します。これは、Web ページ直接宣言することにより接続作成する方法1 つで、具体的に<asp:WebPartManager> 要素内に宣言されています。これは静的接続であるため、2 つカスタム コントロール間の接続は、最初にページ読み込んだ直後作成されます。

コントロール間の接続構成する 2 番目の方法では、ページ<asp:connectionszone> 要素指定します実行時ユーザーページ接続表示モード切り替え1 つカスタム コントロールConnect 動詞クリックすると、接続作成する UI<asp:connectionszone> 要素によって自動的に表示されます。

このページは、プログラムによって接続する3 番目の接続作成方法示しますButton1_Click メソッドで、コードプロバイダ コントロール用の ProviderConnectionPoint オブジェクト作成し、GetProviderConnectionPoints メソッド呼び出してコネクション ポイント詳細取得します。このコードは、コンシューマ コントロールに対して同様のタスク実行し、GetConsumerConnectionPoints メソッド呼び出します。最後にWebPartManager コントロールConnectWebParts メソッド呼び出して新しWebPartConnection オブジェクト作成します

<%@ Page Language="vb" %>
<%@ Register TagPrefix="uc1" 
    TagName="DisplayModeMenuVB"
    Src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="Samples.AspNet.VB.Controls"
 %>

<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">
        <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="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" %>

<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">
        <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="Connect WebPart Controls" 
        OnClick="Button1_Click" 
    Visible="false" />
    </div>
    </form>
</body>
</html>

ブラウザWeb ページ読み込むと、最初接続は既に存在してます。これはこの接続<StaticConnections> 要素内に宣言されているためです。[ZIP Code Provider] コントロール何らかのテキスト入力すると、それがコンシューマ コントロール表示されます。次に2 つコントロール接続解除します。[Display Mode] ドロップダウン リスト コントロール使用してページ接続表示モード変更しますそれぞれの WebPart コントロールで、タイトル バー下向き矢印表示され動詞メニュークリックしそれぞれに [接続] オプションがあることを確認します。これは Connect 動詞で、ページ接続モードにある場合にのみ動詞メニュー表示されます。1 つコントロールConnect 動詞クリックすると、ConnectionsZone コントロール用意されている接続 UI表示されます。[切断] をクリックしコントロール間の静的接続終了します。[Display Mode] コントロール使用してページブラウズ モード戻しますプロバイダもう一度何らかの新しテキスト入力しますコントロール接続解除されているため、コンシューマ コントロールテキスト更新されないことを確認します

次に、上と同じ方法で、もう一度ページ接続表示モード切り替えます1 つコントロールConnect 動詞クリックします。[Create a Connection] リンクをクリックしConnectionsZone コントロール用意されている UI使用してコントロール間の接続作成します。これが、接続作成する 2 番目の方法です。接続構成直後プロバイダ コントロール前回入力したが、コントロール接続解除されていたため表示されなかった文字列が、コンシューマに突然表示されます。これは、接続再作成されたためです。[切断] をクリックし今作成した現在の接続終了しますページブラウズ モード戻しますプロバイダ何らかの新しテキスト入力しテキスト更新されないことを確認します。これは、コントロール接続が再び解除されたためです。

ページ接続表示モード戻しますConnect 動詞クリックする代わりに、[Connect WebPart Controls] をクリックします。これは、接続構成する 3 番目の方法示してます。この方法では、ConnectionsZone コントロール使用しなくても、1 回簡単な手順プログラムによってコントロール接続します接続作成されたため、前回プロバイダ入力した文字列が、コンシューマ コントロールに突然表示されます。

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

WebPartConnection コンストラクタ

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

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

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

Dim instance As New WebPartConnection
public WebPartConnection ()
public:
WebPartConnection ()
public WebPartConnection ()
public function WebPartConnection ()
解説解説

WebPartConnection コンストラクタパブリックであるため、Web ページマークアップ接続宣言するASP.NET パーサーインスタンス作成できます。このコンストラクタ開発者コードでの使用想定していません。

プログラムWebPartConnection オブジェクト作成する場合は、WebPartManager コントロール用意されている WebPartManager.ConnectWebParts メソッドまたは WebPartManager.ConnectWebParts メソッド使用する必要があります。これらのメソッドは、接続作成における多く詳細要件処理しWebPartConnection オブジェクト返します

WebPartConnection クラスWebPartConnection コンストラクタは、IsShared プロパティおよび IsStatic プロパティの値を true設定します。これにより、新し接続既定の状態は静的になり (つまり、含まれる Web ページマークアップ宣言され)、共有されます (ページすべてのユーザー表示されます)。これが、<asp:webpartconnection> 要素ページマークアップ接続宣言して接続追加する場合一般的な手順です。ただし、別の環境では、接続はこれらのプロパティに対して異なる値を持ちます。たとえば、コード接続オブジェクト作成してプログラム接続追加しユーザー既定ユーザー パーソナル化スコープページ表示する場合接続は、動的なユーザー別 (特定のユーザーに対してのみ表示) の接続として作成されます。

メモメモ

IsShared プロパティおよび IsStatic プロパティ読み取り専用です。また、接続性質決定するこれらのプロパティは、接続作成方法 (ページ マークアップによる宣言、独自のコード使用したプログラム、またはユーザー インターフェイス) に応じて WebPartManager コントロールによって内部的に設定されます。

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

WebPartConnection プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Consumer 接続コンシューマ コントロールとして動作する WebPart オブジェクト取得します
パブリック プロパティ ConsumerConnectionPoint 接続コンシューマとして動作するコントロール対すコネクション ポイントとしての役割を果たすオブジェクト取得します
パブリック プロパティ ConsumerConnectionPointID 接続コンシューマ接続ポイントとしての役割を果たすオブジェクトID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ConsumerID 接続コンシューマとして動作する WebPart コントロールID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ID WebPartConnection オブジェクトID取得または設定します
パブリック プロパティ IsActive 現在 WebPartConnection オブジェクト確立されていて、そのプロバイダ コントロールコンシューマ コントロールの間でデータ交換できるかどうかを示す値を取得します
パブリック プロパティ IsShared WebPartConnection オブジェクトすべてのユーザー表示するかまたは現在のユーザーのみに表示するかを示す値を取得または設定します
パブリック プロパティ IsStatic WebPartConnection オブジェクトWeb ページマークアップ宣言されているか、またはプログラム作成されるかを示す値を取得します
パブリック プロパティ Provider Web パーツ接続プロバイダとして動作する WebPart コントロール取得します
パブリック プロパティ ProviderConnectionPoint 接続プロバイダとして動作する WebPart コントロール対すコネクション ポイントとしての役割を果たすオブジェクト取得します
パブリック プロパティ ProviderConnectionPointID 接続プロバイダ コネクション ポイントとしての役割を果たすオブジェクトID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ProviderID 接続プロバイダとして動作する WebPart コントロールID参照する接続プロパティ値を取得または設定します
パブリック プロパティ Transformer Web パーツ接続2 つ異なった互換性のないコネクション ポイントの間でデータ変換するために使用する WebPartTransformer オブジェクト取得します
パブリック プロパティ Transformers Web パーツ コントロール セット内部的に使用する WebPartTransformer オブジェクトコレクション取得します
参照参照

関連項目

WebPartConnection クラス
System.Web.UI.WebControls.WebParts 名前空間
ConnectionPoint クラス
ProviderConnectionPoint クラス
ConsumerConnectionPoint クラス
WebPartManager
ConnectionsZone クラス
WebPartTransformer
ConnectWebParts

その他の技術情報

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

WebPartConnection メソッド


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

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

関連項目

WebPartConnection クラス
System.Web.UI.WebControls.WebParts 名前空間
ConnectionPoint クラス
ProviderConnectionPoint クラス
ConsumerConnectionPoint クラス
WebPartManager
ConnectionsZone クラス
WebPartTransformer
ConnectWebParts

その他の技術情報

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

WebPartConnection メンバ

2 つWebPart コントロール接続構成できるようにするオブジェクト提供します。このクラス継承できません。

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド WebPartConnection WebPartConnection クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Consumer 接続コンシューマ コントロールとして動作する WebPart オブジェクト取得します
パブリック プロパティ ConsumerConnectionPoint 接続コンシューマとして動作するコントロール対すコネクション ポイントとしての役割を果たすオブジェクト取得します
パブリック プロパティ ConsumerConnectionPointID 接続コンシューマ接続ポイントとしての役割を果たすオブジェクトID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ConsumerID 接続コンシューマとして動作する WebPart コントロールID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ID WebPartConnection オブジェクトID取得または設定します
パブリック プロパティ IsActive 現在 WebPartConnection オブジェクト確立されていて、そのプロバイダ コントロールコンシューマ コントロールの間でデータ交換できるかどうかを示す値を取得します
パブリック プロパティ IsShared WebPartConnection オブジェクトすべてのユーザー表示するかまたは現在のユーザーのみに表示するかを示す値を取得または設定します
パブリック プロパティ IsStatic WebPartConnection オブジェクトWeb ページマークアップ宣言されているか、またはプログラム作成されるかを示す値を取得します
パブリック プロパティ Provider Web パーツ接続プロバイダとして動作する WebPart コントロール取得します
パブリック プロパティ ProviderConnectionPoint 接続プロバイダとして動作する WebPart コントロール対すコネクション ポイントとしての役割を果たすオブジェクト取得します
パブリック プロパティ ProviderConnectionPointID 接続プロバイダ コネクション ポイントとしての役割を果たすオブジェクトID参照する接続プロパティ値を取得または設定します
パブリック プロパティ ProviderID 接続プロバイダとして動作する WebPart コントロールID参照する接続プロパティ値を取得または設定します
パブリック プロパティ Transformer Web パーツ接続2 つ異なった互換性のないコネクション ポイントの間でデータ変換するために使用する WebPartTransformer オブジェクト取得します
パブリック プロパティ Transformers Web パーツ コントロール セット内部的に使用する WebPartTransformer オブジェクトコレクション取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebPartConnection クラス
System.Web.UI.WebControls.WebParts 名前空間
ConnectionPoint クラス
ProviderConnectionPoint クラス
ConsumerConnectionPoint クラス
WebPartManager
ConnectionsZone クラス
WebPartTransformer
ConnectWebParts

その他の技術情報

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


このページでは「.NET Framework クラス ライブラリ リファレンス」からWebPartConnectionを検索した結果を表示しています。
Weblioに収録されているすべての辞書からWebPartConnectionを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からWebPartConnection を検索

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

辞書ショートカット

すべての辞書の索引

「WebPartConnection」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS