WebPartConnection.Provider プロパティ
アセンブリ: System.Web (system.web.dll 内)



すべての Web パーツ接続が、コンシューマとプロバイダの 2 つの WebPart コントロールで構成され、Provider プロパティは接続のプロバイダ コントロールへの参照を返します。
接続相手 (コンシューマ コントロール) と同様に、接続を確立するにはプロバイダ コントロールが必要です。プログラムで接続を作成するか、または永続的な形式でページに宣言して接続を作成し、接続のプロバイダとして動作するコントロールを指定する必要があります。

Provider プロパティを使用するコード例を次に示します。
コード例の最初の部分は、インターフェイスのソース コード、およびコンシューマ コントロールとプロバイダ コントロールのソース コードです。コード例を実行するためには、このソース コードをコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みのアセンブリを 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); } } }
コード例の 2 番目の部分は Web ページです。先頭近くに、2 つの動的にコンパイルされた WebPart コントロールのソース コードを参照する Register ディレクティブがあります。ページの <StaticConnections> 要素内に静的接続が宣言されています。<asp:webpartconnection> 要素で、ProviderID 属性にはプロバイダ コントロールに割り当てられている ID が格納されます。これは、静的接続のプロバイダを識別する場合に必要です。Button1_Click メソッドが Provider プロパティにアクセスし、その詳細の一部をラベルに書き込みます。
<%@ Page Language="VB" %> <%@ 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 conn As WebPartConnection = mgr.StaticConnections(0) lbl1.Text = "<h3>Provider Details</h3><br />" & _ "ID: " & conn.Provider.ID & _ "<br />" & _ "Display Title: " & conn.Provider.Title & _ "<br />" & _ "Control type: " & conn.Provider.GetType().FullName 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"> <StaticConnections> <asp:WebPartConnection ID="conn1" ConsumerConnectionPointID="ZipCodeConsumer" ConsumerID="weather1" ProviderConnectionPointID="ZipCodeProvider" ProviderID="zip1" /> </StaticConnections> </asp:WebPartManager> <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="Provider Details" OnClick="Button1_Click" /> <br /> <asp:Label ID="lbl1" runat="server" /> </div> </form> </body> </html>
<%@ Page Language="C#" %> <%@ 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) { WebPartConnection conn = mgr.StaticConnections[0]; lbl1.Text = "<h3>Provider Details</h3><br />" + "ID: " + conn.Provider.ID + "<br />" + "Display Title: " + conn.Provider.Title + "<br />" + "Control type: " + conn.Provider.GetType().FullName; } </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> <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="Provider Details" OnClick="Button1_Click" /> <br /> <asp:Label ID="lbl1" runat="server" /> </div> </form> </body> </html>
ブラウザにページを読み込みます。静的接続は既に作成されています。プロバイダ コントロールに何らかのテキストを入力し、コンシューマ コントロールにそのテキストが表示されることを確認します。[Provider Details] をクリックし、Provider プロパティを通じてアクセスしたプロパティ値の一部を表示します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からWebPartConnection.Provider プロパティを検索する場合は、下記のリンクをクリックしてください。

- WebPartConnection.Provider プロパティのページへのリンク