WebPartManager.GetProviderConnectionPoints(WebPart) 메서드

정의

웹 파트 연결의 공급자 역할을 하는 서버 컨트롤에서 연결 지점으로 사용할 수 있는 ProviderConnectionPoint 개체의 컬렉션을 검색합니다.

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

매개 변수

webPart
WebPart

연결에서 공급자 역할을 하는 서버 컨트롤입니다.

반환

공급자의 연결 지점이 모두 들어 있는 ProviderConnectionPointCollection입니다.

예외

webPart이(가) null인 경우

예제

다음 코드 예제에서는 GetProviderConnectionPoints 메서드를 사용하는 방법을 보여 줍니다.

이 예제에는 다음 네 부분이 있습니다.

  • 웹 파트 페이지의 디스플레이 모드를 변경할 수 있게 해 주는 사용자 정의 컨트롤입니다.

  • 연결할 수 있는 두 개의 사용자 지정 WebPart 컨트롤과 <asp:webpartmanager> 요소가 포함된 웹 페이지입니다.

  • 두 개의 사용자 지정 컨트롤과 사용자 지정 WebPart 인터페이스가 포함된 소스 코드 파일입니다.

  • 예제가 브라우저에서 작동하는 방식에 대한 설명입니다.

코드 예제의 첫 번째 부분은 디스플레이 모드를 변경하기 위한 사용자 컨트롤입니다. 클래스 개요의 예제 섹션에서 사용자 컨트롤에 WebPartManager 대한 소스 코드를 가져올 수 있습니다. 디스플레이 모드 및 사용자 컨트롤의 작동 방식에 대한 자세한 내용은 연습: 웹 파트 페이지에서 디스플레이 모드 변경을 참조하세요.

웹 페이지의 선언적 태그에는 사용자 정의 컨트롤과 사용자 지정 컨트롤 모두에 대한 지시문이 포함되어 Register 있습니다. <asp:webpartmanager> 요소, <asp:webpartzone> 사용자 지정 컨트롤을 포함할 요소 및 <asp:connectionszone> 요소가 있습니다. 메서드에서 Page_Load 코드는 연결이 이미 있는지 확인하고, 그렇지 않은 경우 공급자, 소비자 및 해당 연결 지점을 정의한 다음 속성에서 참조하는 정적 연결 집합에 StaticConnections 새 연결을 추가합니다. 메서드를 ProviderConnectionPointCollection 사용하여 GetProviderConnectionPoints 검색되는 개체는 메서드에 CanConnectWebParts 전달되어 두 컨트롤 간의 연결을 만들 수 있는지 여부를 확인합니다.

<%@ 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>

예제의 세 번째 부분은 컨트롤의 소스 코드입니다. 클래스 개요의 WebPartManager 예제 섹션에서 이 코드와 컴파일 지침을 가져올 수 있습니다.

브라우저에서 웹 페이지를 로드한 후 표시 모드 드롭다운 목록 컨트롤을 클릭하고 연결을 선택하여 페이지를 연결 모드로 전환합니다. 연결 모드는 <asp:connectionszone> 요소를 사용하여 컨트롤 간에 연결을 만들 수 있도록 합니다. 연결 모드에서 우편 번호 컨트롤의 제목 표시줄에서 아래쪽 화살표를 클릭하여 동사 메뉴를 활성화한 다음 연결을 클릭합니다. 연결 UI(사용자 인터페이스)가 나타나면 메서드에 포함된 Page_Load 코드에 의해 연결이 이미 만들어졌는지 확인합니다. 이후 브라우저 세션에서 이 페이지로 돌아가면 이 정적 연결이 이미 설정되며 페이지가 로드될 때마다 다시 만들 필요가 없습니다.

설명

웹 파트 연결에는 항상 정확히 두 개의 컨트롤이 포함됩니다. 하나는 데이터 공급자 역할을 하고 다른 하나는 데이터 소비자 역할을 합니다. 각 컨트롤에는 연결점으로 정의된 하나 이상의 메서드가 있어야 합니다. 공급자 컨트롤의 경우 연결점은 개체입니다 ProviderConnectionPoint .

공급자는 연결을 설정할 수 있도록 항상 하나 이상의 연결 지점이 있어야 합니다. 메서드는 GetProviderConnectionPoints 공급자 컨트롤을 확인하고 모든 연결점의 컬렉션을 검색합니다. 공급자 연결 지점을 검색하는 것은 웹 파트 연결을 구성하는 데 필요한 단계입니다.

적용 대상

추가 정보