WebPartConnection.ProviderConnectionPoint Eigenschaft

Definition

Ruft das Objekt ab, das als Verbindungspunkt für ein WebPart-Steuerelement fungiert, das als Anbieter in einer Verbindung fungiert.Gets the object that serves as a connection point for a WebPart control acting as a provider for a connection.

public:
 property System::Web::UI::WebControls::WebParts::ProviderConnectionPoint ^ ProviderConnectionPoint { System::Web::UI::WebControls::WebParts::ProviderConnectionPoint ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.WebParts.ProviderConnectionPoint ProviderConnectionPoint { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ProviderConnectionPoint : System.Web.UI.WebControls.WebParts.ProviderConnectionPoint
Public ReadOnly Property ProviderConnectionPoint As ProviderConnectionPoint

Eigenschaftswert

ProviderConnectionPoint

Ein ProviderConnectionPoint, der einem Anbietersteuerelement in einer Verbindung zugeordnet ist.A ProviderConnectionPoint associated with the provider control in a connection.

Attribute

Beispiele

Im folgenden Codebeispiel wird die programmgesteuerte Verwendung der- ProviderConnectionPoint Eigenschaft veranschaulicht.The following code example demonstrates the programmatic use of the ProviderConnectionPoint property.

Das Beispiel besteht aus vier Teilen:The example has four parts:

  • Ein Benutzer Steuerelement, mit dem Sie den Webparts Anzeigemodus auf einer Seite ändern können.A user control that enables you to change the Web Parts display mode on a page.

  • Quellcode für eine Schnittstelle und zwei Steuer WebPart Elemente, die als Anbieter und der Consumer für eine Verbindung fungieren.Source code for an interface and two WebPart controls acting as the provider and the consumer for a connection.

  • Eine Webseite zum Hosten aller Steuerelemente und zum Ausführen des Code Beispiels.A Web page to host all the controls and run the code example.

  • Eine Erläuterung zum Ausführen der Beispielseite.An explanation of how to run the example page.

Der erste Teil dieses Code Beispiels ist das Benutzer Steuerelement, das es Benutzern ermöglicht, Anzeigemodi auf einer Webseite zu ändern.The first part of this code example is the user control that enables users to change display modes on a Web page. Speichern Sie den folgenden Quellcode in einer ASCX-Datei. Geben Sie dabei den Dateinamen an, der dem- Src Attribut der- Register Direktive für dieses Benutzer Steuerelement zugewiesen ist, das sich in der Nähe des oberen Rands der hostingwebseite befindet.Save the following source code to an .ascx file, giving it the file name that is assigned to the Src attribute of the Register directive for this user control, which is near the top of the hosting Web page. Ausführliche Informationen zu Anzeigemodi und eine Beschreibung des Quellcodes in diesem Steuerelement finden Sie unter Exemplarische Vorgehensweise : Ändern der Anzeigemodi auf einer Webparts Seite.For details about display modes and a description of the source code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ 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" 
      AssociatedControlID="DisplayModeDropdown"/>
    <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="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" 
      AssociatedControlID="DisplayModeDropdown"/>
    <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>

Der zweite Teil des Code Beispiels ist der Quellcode für die beiden Steuerelemente, die WebPart als Consumer und der Anbieter für die Verbindung fungieren, sowie eine Schnittstelle für die Verbindungspunkte.The second part of the code example is the source code for the two WebPart controls that serve as the consumer and the provider for the connection, and an interface used for the connection points. Damit das Codebeispiel ausgeführt werden kann, müssen Sie diesen Quellcode kompilieren.For the code example to run, you must compile this source code. Sie können Sie explizit kompilieren und die resultierende Assembly in den bin-Ordner der Website oder in den globalen Assemblycache einfügen.You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternativ dazu können Sie den Quellcode in den App_Code Ordner der Website einfügen, wo er zur Laufzeit dynamisch kompiliert wird.Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. In diesem Codebeispiel wird die dynamische Kompilierung verwendet.This code example uses dynamic compilation. Eine exemplarische Vorgehensweise, die das Kompilieren von veranschaulicht, finden Sie unter Exemplarische Vorgehensweise : entwickeln und Verwenden eines benutzerdefinierten Webserver-SteuerElements.For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.

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 (!string.IsNullOrEmpty(input.Text))
      {
        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);
    }
  }
}
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

    Protected Overrides Sub CreateChildControls()
      Controls.Clear()
      DisplayContent = New Label()
      Me.Controls.Add(DisplayContent)

    End Sub

  End Class

End Namespace

Der dritte Teil des Code Beispiels ist der Code für die Webseite, die die Steuerelemente hostet und die Verwendung der- ProviderConnectionPoint Eigenschaft veranschaulicht.The third part of the code example is the code for the Web page that hosts the controls and demonstrates the use of the ProviderConnectionPoint property. In der- Button1_Click Methode werden alle-Objekte erstellt, die zum bilden einer Verbindung erforderlich sind, einschließlich eines- ProviderConnectionPoint Objekts.In the Button1_Click method, all the objects required to form a connection are created, including a ProviderConnectionPoint object. Beachten Sie den-Befehl für die-Methode des- GetProviderConnectionPoints WebPartManager Steuer Elements.Note the call to the GetProviderConnectionPoints method on the WebPartManager control. Die verschiedenen erstellten Objekte werden alle an die- ConnectWebParts Methode übermittelt, um die Verbindung zu erstellen.The various created objects are all passed to the ConnectWebParts method to create the connection. In der Button2_Click -Methode greift der Code auf die ProviderConnectionPoint -Eigenschaft zu und zeigt einige Details zum Verbindungspunkt an.In the Button2_Click method, the code accesses the ProviderConnectionPoint property and displays some details of the connection point.

<%@ 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"];
    WebPartConnection conn1 = mgr.ConnectWebParts(zip1, provPoint,
      weather1, connPoint);
  }

  protected void Button2_Click(object sender, EventArgs e)
  {  
    ProviderConnectionPoint connpoint = 
      mgr.Connections[0].ProviderConnectionPoint;
    lbl2.Text = "<h3>Provider Connection Points Details</h3>" +
      "Display name: " + connpoint.DisplayName +
      "<br />" +
      "Control type: " + connpoint.ControlType.FullName +
      "<br />" +
      "Connection Point ID: " + connpoint.ID +
      "<br />" +
      "Interface type: " + connpoint.InterfaceType.ToString();
  }

  protected void mgr_DisplayModeChanged(object sender, 
    WebPartDisplayModeEventArgs e)
  {
    if (mgr.DisplayMode == WebPartManager.ConnectDisplayMode)
    {
      Button1.Visible = true;
      Button2.Visible = true;
    }
    else
    {
      Button1.Visible = false;
      Button2.Visible = false;
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr" runat="server" 
    OnDisplayModeChanged="mgr_DisplayModeChanged" />
      <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" />
      <br />
      <asp:Button ID="Button2" runat="server" 
        Text="ConnectionPoint Details" 
        OnClick="Button2_Click" 
        Visible="false" /> 
      <br />   
      <asp:Label ID="lbl2" runat="server" />
    </div>
    </form>
</body>
</html>
<%@ 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")
    mgr.ConnectWebParts(zip1, provPoint, weather1, connPoint)

  End Sub

  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    
    Dim connpoint As ProviderConnectionPoint = _
      mgr.Connections(0).ProviderConnectionPoint

    lbl2.Text = "<h3>Provider Connection Points Details</h3>" & _
      "Display name: " & connpoint.DisplayName & _
      "<br />" & _
      "Control type: " & connpoint.ControlType.FullName & _
      "<br />" & _
      "Connection Point ID: " & connpoint.ID & _
      "<br />" & _
      "Interface type: " & connpoint.InterfaceType.ToString()
  End Sub

  Protected Sub mgr_DisplayModeChanged (ByVal sender as Object, _
    ByVal e as WebPartDisplayModeEventArgs)

    If mgr.DisplayMode Is WebPartManager.ConnectDisplayMode Then
      Button1.Visible = True
      Button2.Visible = True
    Else
      Button1.Visible = False
      Button2.Visible = False
    End If

  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr" runat="server"
    OnDisplayModeChanged="mgr_DisplayModeChanged" />
      <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" />
      <br />
      <asp:Button ID="Button2" runat="server" 
        Text="ConnectionPoint Details" 
        OnClick="Button2_Click" 
        Visible="false" /> 
      <br />   
      <asp:Label ID="lbl2" runat="server" />
    </div>
    </form>
</body>
</html>

Nachdem Sie die Seite in einem Browser geladen haben, verwenden Sie das Dropdown Listen-Steuerelement Anzeigemodus , um die Seite in den Verbindungs Modus zu wechseln.After you load the page in a browser, use the Display Mode drop-down list control to switch the page to connect mode. Klicken Sie in einem der Steuerelemente auf das Verbenmenü (dargestellt durch den abwärts Pfeil in der Titelleiste) WebPart , und klicken Sie auf das Connect-Verb.Click the verbs menu (represented by the downward arrow in the title bar) on one of the WebPart controls, and click the connect verb. Verwenden Sie die Schaltfläche WebPart-Steuerelemente verbinden oder die bereitgestellte Verbindungs Benutzeroberfläche, um eine Verbindung zwischen den beiden Steuerelementen zu erstellen.Use the Connect WebPart Controls button, or the provided connection UI, to create a connection between the two controls. Klicken Sie auf die Schaltfläche " ConnectionPoint Details ", um den Code auszuführen, der die ProviderConnectionPoint Eigenschaft veranschaulicht.Click the ConnectionPoint Details button to run the code that demonstrates the ProviderConnectionPoint property.

Hinweise

Einer der erforderlichen Schritte zum Erstellen einer Verbindung zwischen zwei WebPart Steuerelementen besteht darin, für jedes Steuerelement Verbindungspunkte zu erstellen.One of the required steps for creating a connection between two WebPart controls is to create connection points for each control. Der Anbieter Verbindungspunkt ist ein Objekt, das die Informationen zum Herstellen einer Verbindung mit dem Steuerelement enthält, das als Anbieter fungiert.The provider connection point is an object that contains the information about how to connect to the control acting as a provider. Im Quellcode des Anbieters muss eine der Methoden mit dem-Attribut identifiziert werden ConnectionProvider .In the provider's source code, one of the methods must be identified with the ConnectionProvider attribute. Der ProviderConnectionPoint , der einem Anbieter Steuerelement zugeordnet ist, enthält Details zur Methode und zum-Attribut, einschließlich einer ID für die-Methode, einen anzeigen Amen zur Verwendung in der Benutzeroberfläche (UI) und den Typ der Schnittstellen Instanz, der von der Methode an ein Consumersteuerelement zurückgegeben werden kann.The ProviderConnectionPoint that is associated with a provider control contains details about the method and the attribute, including an ID for the method, a display name for use in the user interface (UI), and what type of interface instance the method can return to a consumer control. Dieser Satz von Informationen über den Anbieter, seine Methode zum bilden von Verbindungen und der Typ der Schnittstelle, die er bereitstellt, bildet zusammen einen Anbieter Verbindungspunkt.This set of information about the provider, its method for forming connections, and the type of interface it provides, collectively forms a provider connection point.

Standardmäßig kann eine eine ConsumerConnectionPoint Verbindung mit nur einem ProviderConnectionPoint Objekt gleichzeitig herstellen.By default, a ConsumerConnectionPoint can connect to only one ProviderConnectionPoint object at a time. Ein Consumer könnte mehrere Methoden als mögliche Consumerverbindungspunkte identifizieren, aber ein Consumer kann nur an einer Verbindung als Consumer teilnehmen (daher kann nur einer seiner Consumerverbindungspunkte gleichzeitig aktiv sein).A consumer could have multiple methods identified as possible consumer connection points, but a consumer can only participate in one connection as a consumer (hence, only one of its consumer connection points can be active) at a time. Im Gegensatz dazu ProviderConnectionPoint kann ein standardmäßig eine Verbindung mit einer beliebigen Anzahl von ConsumerConnectionPoint Objekten herstellen.In contrast, a ProviderConnectionPoint can connect to any number of ConsumerConnectionPoint objects by default. Beispielsweise könnte ein Anbieter Steuerelement, das eine Postleitzahl bereitstellt, mit mehreren Consumersteuerelementen verbunden werden, die eine Postleitzahl verwenden, um verschiedene Arten von Daten basierend auf einer Postleitzahl zu erstellen, wie z. b. Wetterdaten, Nachrichten usw.For example, a provider control that provides a postal code could be connected to multiple consumer controls that use a postal code to create various kinds of data based on a postal code, such as weather data, news, and so on. Dieses Standardverhalten kann durch Überschreiben der- AllowsMultipleConnections Eigenschaft für das ConnectionProviderAttribute Attribut geändert werden.This default behavior can be changed by overriding the AllowsMultipleConnections property on the ConnectionProviderAttribute attribute.

Gilt für:

Weitere Informationen