WebPartManager.WebParts 속성

정의

웹 페이지에서 WebPart 컨트롤이 관리하는 모든 WebPartManager 컨트롤에 대한 참조를 가져옵니다.

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

속성 값

WebPartCollection

WebPartCollection 컨트롤 집합에 대한 참조가 들어 있는 WebPart입니다.

특성

예제

다음 코드 예제에서는 프로그래밍 방식으로 속성을 사용 하 여 WebParts 개별 WebPart 컨트롤에 액세스 하는 방법을 보여 줍니다. 웹 페이지의 선언적 태그에는 요소 내에 <asp:webpartzone> 두 개의 표준 ASP.NET 서버 컨트롤이 있습니다. 클래스에서 WebPart 상속되지는 않지만 영역에 있으므로 런타임에 개체로 GenericWebPart 래핑되므로 속성에서 참조하는 컬렉션에 WebParts 포함됩니다. 이 영역에서 사용자 지정 WebPart 컨트롤, 사용자 정의 컨트롤 또는 사용자 지정 서버 컨트롤을 추가할 수도 있으며 동일한 방식으로 처리됩니다.

<%@ Page Language="C#" %>

<!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)
  {
    Label1.Text = "WebPart count:  " +
      WebPartManager1.WebParts.Count.ToString();
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    WebPartManager1.WebParts["Calendar1"].ChromeType = 
      PartChromeType.BorderOnly;
  }
</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="WebPartManager1" runat="server" />    
    <div>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links"
            ExportMode="All">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="WebPart Count" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Hide Calendar Title" 
        OnClick="Button2_Click" />  
      <br />
      <asp:Label ID="Label1" runat="server" text="" />
    </div>
    </form>
</body>
</html>
<%@ Page Language="vb" %>

<!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)
    
    Label1.Text = "WebPart count:  " & _
      WebPartManager1.WebParts.Count.ToString()
  End Sub

  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    
    WebPartManager1.WebParts("Calendar1").ChromeType = _
      PartChromeType.BorderOnly

  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="WebPartManager1" runat="server" />    
    <div>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links"
            ExportMode="All">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="WebPart Count" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Hide Calendar Title" 
        OnClick="Button2_Click" />  
      <br />
      <asp:Label ID="Label1" runat="server" text="" />
    </div>
    </form>
</body>
</html>

코드 예제가 작동하려면 Web.config 파일에 설정을 추가하여 웹 파트 설명 파일을 내보낼 수 있도록 해야 합니다. 이 코드 예제의 웹 페이지와 동일한 디렉터리에 Web.config 파일이 있는지 확인합니다. <system.web> 섹션 내에서 다음 태그와 enableExport 같이 특성이 <webParts> 설정된 true요소가 있는지 확인합니다.

<webParts enableExport="true">

...

</webParts>

페이지를 브라우저에 로드한 후 WebPart Count 단추를 클릭하면 코드에서 이 속성을 사용하여 WebParts 컬렉션의 컨트롤 수를 반환합니다. 일정 제목 숨기기 단추를 클릭하면 코드는 제목이 아닌 테두리만 사용하여 렌더링되도록 달력을 변경합니다.

설명

WebParts 속성은 컨트롤에서 WebPartManager 페이지의 영역 내에 WebPartZoneBase 포함된 모든 WebPart 컨트롤을 추적하는 데 사용됩니다. 컬렉션은 읽기 전용이지만 컬렉션을 통해 개별 WebPart 컨트롤에 액세스하고 프로그래밍 방식으로 변경할 수 있습니다.

참고

컨트롤이 WebPart 영역 외부의 WebPartZone 페이지에 배치되어 컨트롤이 컨트롤에 의해 WebPartManager 추적되거나 해당 컬렉션에서 참조되지 않도록 할 수 있습니다 WebParts . 그러나 영역 외부에서 컨트롤을 WebPart 사용할 이유가 거의 없습니다. 해당 컨트롤이 웹 파트 기능을 잃고 일반 서버 컨트롤 역할을 하기 때문입니다.

사용자 지정 컨트롤, 표준 ASP.NET 컨트롤, 사용자 정의 컨트롤 또는 사용자 지정 WebPart 서버 컨트롤 등 영역에 배치할 수 있는 모든 유형의 컨트롤은 런타임에 컨트롤로 WebPart 처리할 수 있습니다. 컨트롤이 아닌 WebPart 컨트롤이 영역에 배치 WebPartZone 되는 경우 런타임에 ASP.NET 컨트롤이 실제 WebPart 컨트롤 GenericWebPart 로 동작할 수 있도록 컨트롤을 개체로 래핑합니다. 따라서 속성을 사용하면 컨트롤이 WebParts WebPartManager 클래스에서 파생되는지 여부에 관계없이 모든 유형의 서버 컨트롤을 WebPart 추적할 수 있습니다.

적용 대상