WebPartManager.Zones 속성

정의

웹 페이지의 WebPartZoneBase 영역이 모두 들어 있는 컬렉션에 대한 참조를 가져옵니다.

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

속성 값

WebPartZoneCollection

WebPartZoneCollection 영역 집합을 참조하는 WebPartZoneBase입니다.

특성

예제

다음 코드 예제에서는 속성을 WebPartZoneBase 프로그래밍 방식으로 개별 Zones 영역 컨트롤에 액세스 하는 방법을 보여 줍니다. 웹 페이지의 선언적 태그에는 각각 서버 컨트롤을 포함하는 두 <asp:webpartzone> 가지 요소가 있습니다. <script> 페이지의 섹션에서 코드는 속성을 사용하여 Zones 개별 영역에 액세스하고 모든 영역 ID를 나열한 다음 두 번째 영역에서 배경색을 변경합니다.

<%@ 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)
  {
    foreach (WebPartZone zone in WebPartManager1.Zones)
    {
      Label1.Text += zone.ID + "<br />";
    }
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    WebPartManager1.Zones["WebPartZone2"].BackColor = System.Drawing.Color.LightBlue;
  }
</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>
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />        
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="List Zone IDs" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Change Zone BackColor" 
        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)
    Dim zone As WebPartZone
    For Each zone In WebPartManager1.Zones
      Label1.Text += zone.ID & "<br />"
    Next
  End Sub

  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    WebPartManager1.Zones("WebPartZone2").BackColor = _
      System.Drawing.Color.LightBlue
  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>
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />        
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="List Zone IDs" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Change Zone BackColor" 
        OnClick="Button2_Click" />  
      <br />
      <asp:Label ID="Label1" runat="server" text="" />
    </div>
    </form>
</body>
</html>

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

<webParts enableExport="true">

...

</webParts>

페이지를 브라우저에 로드한 후 영역 ID 나열 단추를 클릭하면 코드는 이 속성을 사용하여 Zones 컬렉션에 있는 모든 영역의 ID를 나열합니다. 영역 백콜러 변경 단추를 클릭하면 코드에서 두 번째 영역의 배경색을 변경합니다.

설명

Zones 속성은 컨트롤에서 WebPartManager 웹 페이지의 영역을 추적하는 WebPartZoneBase 데 사용됩니다. 속성이 모든 유형의 영역을 참조하지는 않습니다. 는 영역을 포함하여 WebPartZone 클래스에서 WebPartZoneBase 파생되는 영역만 참조합니다.

속성에서 참조하는 컬렉션은 읽기 전용이지만 이 컬렉션을 사용하여 컬렉션의 개별 개체에 액세스하고 프로그래밍 방식으로 작업할 수 있습니다.

적용 대상