WebPartManager.Zones プロパティ

定義

Web ページ上のすべての 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

属性

次のコード例は、プロパティをプログラムで使用して個々WebPartZoneBaseZonesゾーン コントロールにアクセスする方法を示しています。 Web ページの宣言型マークアップには、それぞれサーバー コントロールを含む 2 つの <asp:webpartzone> 要素があることに注意してください。 ページの <script> セクションでは、このプロパティを Zones 使用して個々のゾーンにアクセスし、すべてのゾーン ID を一覧表示し、2 番目のゾーンの背景色を変更します。

<%@ 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 パーツ記述ファイルのエクスポートを有効にする必要があることに注意してください。 このコード例の Web ページと同じディレクトリにWeb.config ファイルがあることを確認します。 セクション内に<system.web>、次の<webParts>マークアップのように属性が設定trueされた要素enableExportがあることを確認します。

<webParts enableExport="true">

...

</webParts>

ブラウザーにページを読み込んだ後、[ List Zone ID](ゾーン ID の一覧表示 ) ボタンをクリックすると、このプロパティを Zones 使用してコレクション内のすべてのゾーンの ID が一覧表示されます。 [ Change Zone BackColor](ゾーンの戻る色の変更 ) ボタンをクリックすると、コードによって 2 番目のゾーンの背景色が変更されます。

注釈

このプロパティは Zones 、Web ページ上の WebPartManager ゾーンを WebPartZoneBase 追跡するためにコントロールによって使用されます。 プロパティはすべての種類のゾーンを参照しているわけではないことに注意してください。ゾーンを含めWebPartZone、クラスから派生したWebPartZoneBaseゾーンのみを参照します。

プロパティによって参照されるコレクションは読み取り専用ですが、それを使用してコレクション内の個々のオブジェクトにアクセスし、プログラムで操作できます。

適用対象