WebPartManager.GetProviderConnectionPoints(WebPart) Método

Definição

Recupera a coleção de objetos ProviderConnectionPoint que podem atuar como pontos de conexão de um controle de servidor que atua como um provedor em uma conexão de Web Parts.Retrieves the collection of ProviderConnectionPoint objects that can act as connection points from a server control that is acting as a provider within a Web Parts connection.

public:
 virtual System::Web::UI::WebControls::WebParts::ProviderConnectionPointCollection ^ GetProviderConnectionPoints(System::Web::UI::WebControls::WebParts::WebPart ^ webPart);
public virtual System.Web.UI.WebControls.WebParts.ProviderConnectionPointCollection GetProviderConnectionPoints (System.Web.UI.WebControls.WebParts.WebPart webPart);
abstract member GetProviderConnectionPoints : System.Web.UI.WebControls.WebParts.WebPart -> System.Web.UI.WebControls.WebParts.ProviderConnectionPointCollection
override this.GetProviderConnectionPoints : System.Web.UI.WebControls.WebParts.WebPart -> System.Web.UI.WebControls.WebParts.ProviderConnectionPointCollection
Public Overridable Function GetProviderConnectionPoints (webPart As WebPart) As ProviderConnectionPointCollection

Parâmetros

webPart
WebPart

Um controle de servidor que atua como um provedor em uma conexão.A server control that is acting as a provider in a connection.

Retornos

ProviderConnectionPointCollection

Um ProviderConnectionPointCollection que contém todos os pontos de conexão no provedor.A ProviderConnectionPointCollection that contains all connection points in the provider.

Exceções

webPart é null.webPart is null.

Exemplos

O exemplo de código a seguir demonstra como usar o GetProviderConnectionPoints método.The following code example demonstrates how to use the GetProviderConnectionPoints method.

O exemplo tem quatro partes:The example has four parts:

  • Um controle de usuário que permite alterar modos de exibição em uma página Web Parts.A user control that enables you to change display modes on a Web Parts page.

  • Uma página da Web que contém dois WebPart controles personalizados que podem ser conectados e um <asp:webpartmanager> elemento.A Web page that contains two custom WebPart controls that can be connected, and an <asp:webpartmanager> element.

  • Um arquivo de código-fonte que contém dois WebPart controles personalizados e uma interface personalizada.A source code file that contains two custom WebPart controls and a custom interface.

  • Uma explicação de como o exemplo funciona em um navegador.An explanation of how the example works in a browser.

A primeira parte do exemplo de código é o controle de usuário para alterar os modos de exibição.The first part of the code example is the user control for changing display modes. Você pode obter o código-fonte do controle de usuário na seção de exemplo da WebPartManager classe visão geral.You can obtain the source code for the user control from the Example section of the WebPartManager class overview. Para obter mais informações sobre modos de exibição e como o controle de usuário funciona, consulte passo a passos: Alterando modos de exibição em uma página de Web Parts.For more information about display modes and how the user control works, see Walkthrough: Changing Display Modes on a Web Parts Page.

A marcação declarativa para a página da Web contém Register diretivas para o controle de usuário e os controles personalizados.The declarative markup for the Web page contains Register directives for both the user control and the custom controls. Há um <asp:webpartmanager> elemento, um <asp:webpartzone> elemento para conter os controles personalizados e um <asp:connectionszone> elemento.There is an <asp:webpartmanager> element, an <asp:webpartzone> element to contain the custom controls, and an <asp:connectionszone> element. Observe que, no Page_Load método, o código verifica se uma conexão já existe e, caso contrário, define um provedor, um consumidor e seus respectivos pontos de conexão e, em seguida, adiciona uma nova conexão ao conjunto de conexões estáticas referenciadas pela StaticConnections propriedade.Notice that in the Page_Load method, the code checks to see whether a connection already exists and, if not, defines a provider, a consumer, and their respective connection points, and then adds a new connection to the set of static connections referenced by the StaticConnections property. Observe que o ProviderConnectionPointCollection objeto recuperado usando o GetProviderConnectionPoints método é passado para o CanConnectWebParts método para determinar se uma conexão entre os dois controles pode ser criada.Note that the ProviderConnectionPointCollection object that is retrieved by using the GetProviderConnectionPoints method is then passed to the CanConnectWebParts method to determine whether a connection between the two controls can be created.

<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="ConnectionSampleCS"%>

<!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 Page_Load(object sender, EventArgs e)
  {
    
    // Define provider, consumer, and connection points.
    WebPart provider = mgr.WebParts["zip1"];
    ProviderConnectionPoint provConnPoint =
      mgr.GetProviderConnectionPoints(provider)["ZipCodeProvider"];
    WebPart consumer = mgr.WebParts["weather1"];
    ConsumerConnectionPoint consConnPoint =
      mgr.GetConsumerConnectionPoints(consumer)["ZipCodeConsumer"];
    
    // Check whether the connection already exists.
    if (mgr.CanConnectWebParts(provider, provConnPoint,
      consumer, consConnPoint))
    {
      // Create a new static connection.
      WebPartConnection conn = new WebPartConnection();
      conn.ID = "staticConn1";
      conn.ConsumerID = "weather1";
      conn.ConsumerConnectionPointID = "ZipCodeConsumer";
      conn.ProviderID = "zip1";
      conn.ProviderConnectionPointID = "ZipCodeProvider";
      mgr.StaticConnections.Add(conn);
    }
 }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
      <asp:WebPartManager ID="mgr" runat="server" />   
    <div>
      <uc1:DisplayModeMenuCS ID="displaymode1" 
        runat="server" />
      <!-- Reference consumer and provider controls 
           in a zone. -->
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <aspSample:ZipCodeWebPart ID="zip1" 
            runat="server" 
            Title="Zip Code Control"/>
          <aspSample:WeatherWebPart ID="weather1" 
            runat="server" 
            Title="Weather Control" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <!-- Add a ConnectionsZone so users can connect 
           controls. -->
      <asp:ConnectionsZone ID="ConnectionsZone1" 
        runat="server" />
    </div>
    </form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls" 
  Assembly="ConnectionSampleVB"%>

<!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 Page_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    
    ' Define provider, consumer, and connection points.
    Dim provider As WebPart = mgr.WebParts("zip1")
    Dim provConnPoint As ProviderConnectionPoint = _
      mgr.GetProviderConnectionPoints(provider)("ZipCodeProvider")
    Dim consumer As WebPart = mgr.WebParts("weather1")
    Dim consConnPoint As ConsumerConnectionPoint = _
      mgr.GetConsumerConnectionPoints(consumer)("ZipCodeConsumer")
    
    ' Check whether the connection already exists.
    If mgr.CanConnectWebParts(provider, provConnPoint, _
      consumer, consConnPoint) Then
      ' Create a new static connection.
      Dim conn As New WebPartConnection()
      conn.ID = "staticConn1"
      conn.ConsumerID = "weather1"
      conn.ConsumerConnectionPointID = "ZipCodeConsumer"
      conn.ProviderID = "zip1"
      conn.ProviderConnectionPointID = "ZipCodeProvider"
      mgr.StaticConnections.Add(conn)
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
      <asp:WebPartManager ID="mgr" runat="server" />   
    <div>
      <uc1:DisplayModeMenuVB ID="displaymode1" 
        runat="server" />
      <!-- Reference consumer and provider controls 
           in a zone. -->
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <aspSample:ZipCodeWebPart ID="zip1" 
            runat="server" 
            Title="Zip Code Control"/>
          <aspSample:WeatherWebPart ID="weather1" 
            runat="server" 
            Title="Weather Control" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <!-- Add a ConnectionsZone so users can connect 
           controls. -->
      <asp:ConnectionsZone ID="ConnectionsZone1" 
        runat="server" />
    </div>
    </form>
</body>
</html>

A terceira parte do exemplo é o código-fonte para os controles.The third part of the example is the source code for the controls. Você pode obter esse código e instruções para compilá-lo, na seção de exemplo da WebPartManager classe visão geral.You can obtain this code, and instructions for compiling it, from the Example section of the WebPartManager class overview.

Depois de carregar a página da Web em um navegador, clique no controle de lista suspensa modo de exibição e selecione conectar para alternar a página para o modo de conexão.After you have loaded the Web page in a browser, click the Display Mode drop-down list control and select Connect to switch the page to connect mode. O modo de conexão usa o <asp:connectionszone> elemento para permitir que você crie conexões entre controles.Connect mode uses the <asp:connectionszone> element to enable you to create connections between controls. No modo de conexão, clique na seta para baixo na barra de título do controle de CEP para ativar o menu de verbos e clique em conectar.In connect mode, click the downward arrow in the title bar of the ZIP Code control to activate its verbs menu, and then click Connect. Depois que a interface do usuário da conexão for exibida, observe que uma conexão já foi criada pelo código contido no Page_Load método.After the connection user interface (UI) appears, notice that a connection has already been created by the code contained in the Page_Load method. Se você retornar a esta página em uma sessão de navegador posterior, essa conexão estática já será estabelecida e não precisará ser recriada sempre que a página for carregada.If you return to this page in a later browser session, this static connection will already be established and will not need to be recreated each time the page loads.

Comentários

Uma conexão Web Parts sempre envolve exatamente dois controles, um atuando como o provedor de dados, o outro atuando como consumidor de dados.A Web Parts connection always involves exactly two controls, one acting as the provider of data, the other acting as the consumer of data. Cada controle deve ter um ou mais métodos definidos como pontos de conexão.Each control must have one or more methods that are defined as connection points. No caso de um controle de provedor, seus pontos de conexão são ProviderConnectionPoint objetos.In the case of a provider control, its connection points are ProviderConnectionPoint objects.

Um provedor sempre deve ter pelo menos um ponto de conexão para poder estabelecer uma conexão.A provider must always have at least one connection point to be able to establish a connection. O GetProviderConnectionPoints método verifica um controle de provedor e recupera uma coleção de todos os seus pontos de conexão.The GetProviderConnectionPoints method checks a provider control and retrieves a collection of all its connection points. Recuperar os pontos de conexão do provedor é uma etapa necessária na formação de uma conexão Web Parts.Retrieving the provider connection points is a necessary step in forming a Web Parts connection.

Aplica-se a

Confira também