WebPartManager.StaticConnections 속성

정의

웹 페이지에 정적 연결로 정의된 모든 WebPartConnection 개체의 컬렉션에 대한 참조를 가져옵니다.

public:
 property System::Web::UI::WebControls::WebParts::WebPartConnectionCollection ^ StaticConnections { System::Web::UI::WebControls::WebParts::WebPartConnectionCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.WebParts.WebPartConnectionCollection StaticConnections { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.StaticConnections : System.Web.UI.WebControls.WebParts.WebPartConnectionCollection
Public ReadOnly Property StaticConnections As WebPartConnectionCollection

속성 값

WebPartConnectionCollection

페이지의 정적 연결이 모두 들어 있는 WebPartConnectionCollection입니다.

특성

예제

다음 코드 예제에서는 속성의 프로그래밍 방식으로 사용 하는 방법을 보여 줍니다 StaticConnections .

코드 예제에는 다음 4개의 부분이 있습니다.

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

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

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

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

다음 코드에는 예제의 웹 페이지 부분만 포함됩니다. 또한 클래스 개요의 예제 섹션에서 사용자 지정 사용자 정의 컨트롤 및 사용자 지정 컨트롤 및 인터페이스에 대한 소스 코드와 같은 예제의 WebPartManager 처음 두 부분을 가져와야 합니다. 이 항목에서는 컨트롤을 컴파일하는 WebPart 옵션도 설명합니다.

코드 예제의 세 번째 부분은 웹 페이지입니다. 페이지에 대한 선언적 태그에는 사용자 정의 컨트롤과 사용자 지정 컨트롤 모두에 대한 지시문이 포함되어 Register 있습니다. <asp:webpartmanager> 요소, <asp:webpartzone> 사용자 지정 컨트롤을 포함할 요소 및 <asp:connectionszone> 요소가 있습니다. 메서드에서 Page_Load 코드는 연결이 이미 있는지 확인하고, 그렇지 않은 경우 공급자, 소비자 및 해당 연결 지점을 정의한 다음 속성에서 참조하는 정적 연결 집합에 StaticConnections 새 연결을 추가합니다.

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

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

설명

StaticConnections 속성은 컨트롤에서 WebPartManager 페이지의 모든 정적 연결을 추적하고 관리하는 데 사용됩니다. 동적 연결과 달리 정적 연결은 페이지가 렌더링될 때마다 페이지에 추가할 필요가 없습니다.

이 속성에서 참조하는 컬렉션에는 페이지에 있는 모든 정적 연결이 프로그래밍 방식으로 생성되거나 페이지 태그의 요소로 <asp:webpartconnection> 지정되어 있습니다.

적용 대상

추가 정보