WebPartZoneCollectionとは? わかりやすく解説

WebPartZoneCollection クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

WebPartZone コントロールの読み取り専用のコレクションを含みます。

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 WebPartZoneCollection
    Inherits ReadOnlyCollectionBase
Dim instance As WebPartZoneCollection
public sealed class WebPartZoneCollection :
 ReadOnlyCollectionBase
public ref class WebPartZoneCollection sealed
 : public ReadOnlyCollectionBase
public final class WebPartZoneCollection extends
 ReadOnlyCollectionBase
public final class WebPartZoneCollection extends
 ReadOnlyCollectionBase
解説解説

WebPartZoneCollection クラスには、Web パーツ ページに存在する WebPartZone コントロールのコレクションが含まれます。主に WebPartManager コントロールによって、すべてのゾーンの追跡および管理に使用されます。WebPartManager コントロールは、ページ上のゾーンのコレクションへの参照を、その読み取り専用の Zones プロパティに保持します。

WebPartZoneCollection クラスは、複数のゾーンまたはその内容に対して同時に操作を実行する場合、または特定のゾーンを検索してその内容を確認または変更する場合に便利です。ゾーン自体のコレクションは読み取り専用で、コレクション オブジェクト自体のサイズは変更できませんが、コレクション内の個別のゾーンへの参照を取得することはできます。また、個別のゾーン オブジェクトへの参照を保持している場合はそのプロパティ値を変更できます。

WebPartZoneCollection クラスには、2 つのコンストラクタがあります。1 つ目の WebPartZoneCollection は、新しい WebPartZoneCollection の空のインスタンスを初期化するだけです。2 つ目の WebPartZoneCollection(ICollection) は、ゾーンの既存のコレクションを渡すことによってコレクションを初期化します。

WebPartZoneCollection クラスには、Item プロパティが含まれています。このプロパティでは、文字列識別子を渡すことによってコレクション内の WebPartZone コントロールを検索できます。ゾーンを検索するには、文字列識別子と WebPartZoneBase ゾーンの ID プロパティの値が照合されます。

WebPartZoneCollection クラスには、その内容の確認またはアクセスに便利なメソッドも複数あります。Contains メソッドは、特定のゾーンがコレクションに存在するかどうかを判断します。CopyTo メソッドは、コレクションを WebPartZoneBase オブジェクトの配列にコピーします。最後に、IndexOf メソッドは、コレクション内の特定のゾーンのインデックスを返します。

使用例使用例

WebPartZoneCollection クラスの使用方法を示すコード例を次に示します。コード例は、3 つの部分で構成されます。2 つがコード セクション、残りが例の実行方法の説明です。

コード例の最初の部分は、それぞれにサーバー コントロールを 1 つ含む 3 つの WebPartZone コントロールがある Web ページです。これらのサーバー コントロールはすべて標準の ASP.NET コントロールですが、WebPartZone ゾーン内に配置されているので、実行時には WebPart コントロールとして機能できます。

<%@ Page Language="vb" 
    Codefile="webpartzonecollection_overview.vb" 
    Inherits="webpartzonecollection_overview"
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<html  >
<head id="Head1" runat="server">
    <title>WebPartZoneCollection Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:WebPartManager ID="mgr" runat="server"
 />
    <asp:Table ID="Table1" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Label ID="lblZone1" runat="server"
 Font-Bold="true">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" runat="server"
 Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink" 
                Title="Favorite Links" CatalogIconImageUrl="Mine.gif">
                <asp:ListItem Value="http://msdn.microsoft.com">
                  MSDN
                </asp:ListItem>
                <asp:ListItem Value="http://www.asp.net">
                  ASP.NET
                </asp:ListItem>
                <asp:ListItem Value="http://www.msn.com">
                  MSN
                </asp:ListItem>
              </asp:BulletedList>      
            </ZoneTemplate>
          </asp:WebPartZone>
          <div>
          <asp:Label ID="lblZone2" runat="server"
 Font-Bold="true">
            WebPartZone2 Contents
          </asp:Label>          
          </div>
          <asp:WebPartZone ID="WebPartZone2" runat="server"
 Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" runat="server"
 
                Title="My Calendar" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top">
 
          <asp:Label ID="lblZone3" runat="server"
 Font-Bold="true">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table2"
 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell>Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell>Extension</asp:TableHeaderCell>
                </asp:TableHeaderRow>
                <asp:TableRow>
                  <asp:TableCell>Alberts, Amy</asp:TableCell>
                  <asp:TableCell>x9764</asp:TableCell>
                </asp:TableRow>                
                <asp:TableRow>
                  <asp:TableCell>Hanif, Karim</asp:TableCell>
                  <asp:TableCell>x3240</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                  <asp:TableCell>Penor, Lori</asp:TableCell>
                  <asp:TableCell>x4165</asp:TableCell>
                </asp:TableRow>
              </asp:Table>
            </ZoneTemplate>
          </asp:WebPartZone>
        </asp:TableCell>
      </asp:TableRow>
    </asp:Table>
    </div>
    <hr />
    <asp:Table ID="Table3" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Button ID="Button1" runat="server"
 Width ="200" 
            Text="Total Zone Count" OnClick="Button1_Click"
 />
          <br />
          <asp:Button ID="Button2" runat="server"
 Width ="200"
            Text="Coll. Contains WebPartZone2" OnClick="Button2_Click"
 />
          <br />
          <asp:Button ID="Button3" runat="server"
 Width ="200"
            Text="Zone Names from Array" OnClick="Button3_Click"
 />
          <br />
          <asp:Button ID="Button4" runat="server"
 Width ="200"
            Text="WebPartZone1 Index" OnClick="Button4_Click"
 />  
          <br />
          <asp:Button ID="Button5" runat="server"
 Width ="200"
            Text="Toggle Verb Render Mode" OnClick="Button5_Click"
 />
        </asp:TableCell>
        <asp:TableCell HorizontalAlign="right"
 Width="200" 
          VerticalAlign="top">
          <asp:Label ID="Label1" runat="server"
 Font-Bold="true" />
        </asp:TableCell>  
      </asp:TableRow>
    </asp:Table>
    </form>
</body>
</html>
<%@ Page Language="C#" 
    Codefile="webpartzonecollection_overview.cs" 
    Inherits="webpartzonecollection_overview" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<html  >
<head runat="server">
    <title>WebPartZoneCollection Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:WebPartManager ID="mgr" runat="server" />
    <asp:Table runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Label ID="lblZone1" runat="server" Font-Bold="true">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" runat="server"
 Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink" 
                Title="Favorite Links" CatalogIconImageUrl="Mine.gif">
                <asp:ListItem Value="http://msdn.microsoft.com">
                  MSDN
                </asp:ListItem>
                <asp:ListItem Value="http://www.asp.net">
                  ASP.NET
                </asp:ListItem>
                <asp:ListItem Value="http://www.msn.com">
                  MSN
                </asp:ListItem>
              </asp:BulletedList>      
            </ZoneTemplate>
          </asp:WebPartZone>
          <div>
          <asp:Label ID="lblZone2" runat="server" Font-Bold="true">
            WebPartZone2 Contents
          </asp:Label>          
          </div>
          <asp:WebPartZone ID="WebPartZone2" runat="server"
 Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" runat="server"
 
                Title="My Calendar" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top"> 
          <asp:Label ID="lblZone3" runat="server" Font-Bold="true">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table1" 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell>Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell>Extension</asp:TableHeaderCell>
                </asp:TableHeaderRow>
                <asp:TableRow>
                  <asp:TableCell>Alberts, Amy</asp:TableCell>
                  <asp:TableCell>x9764</asp:TableCell>
                </asp:TableRow>                
                <asp:TableRow>
                  <asp:TableCell>Hanif, Karim</asp:TableCell>
                  <asp:TableCell>x3240</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                  <asp:TableCell>Penor, Lori</asp:TableCell>
                  <asp:TableCell>x4165</asp:TableCell>
                </asp:TableRow>
              </asp:Table>
            </ZoneTemplate>
          </asp:WebPartZone>
        </asp:TableCell>
      </asp:TableRow>
    </asp:Table>
    </div>
    <hr />
    <asp:Table runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Button ID="Button1" runat="server" Width ="200"
 
            Text="Total Zone Count" OnClick="Button1_Click" />
          <br />
          <asp:Button ID="Button2" runat="server" Width ="200"
            Text="Coll. Contains WebPartZone2" OnClick="Button2_Click"
 />
          <br />
          <asp:Button ID="Button3" runat="server" Width ="200"
            Text="Zone Names from Array" OnClick="Button3_Click"
 />
          <br />
          <asp:Button ID="Button4" runat="server" Width ="200"
            Text="WebPartZone1 Index" OnClick="Button4_Click"
 />  
          <br />
          <asp:Button ID="Button5" runat="server" Width ="200"
            Text="Toggle Verb Render Mode" OnClick="Button5_Click"
 />
        </asp:TableCell>
        <asp:TableCell HorizontalAlign="right" Width="200"
 
          VerticalAlign="top">
          <asp:Label ID="Label1" runat="server" Font-Bold="true"
 />
        </asp:TableCell>  
      </asp:TableRow>
    </asp:Table>
    </form>
</body>
</html>

コード例の 2 番目の部分は、WebPartZoneCollection クラスの使用を示すコードを含む部分クラスです。このコードは、Web ページのイベントを処理します。

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls


Partial Public Class webpartzonecollection_overview

  Inherits Page

  Protected Sub Button1_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = "WebPartZone Count:  " & mgr.Zones.Count

  End Sub


  Protected Sub Button2_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString()

  End Sub

  Protected Sub Button3_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
    Label1.Text = String.Empty
    Dim zoneArray(mgr.Zones.Count) As WebPartZoneBase
    mgr.Zones.CopyTo(zoneArray, 0)
    Label1.Text = zoneArray(2).ID
    Label1.Text += ", " & zoneArray(1).ID
    Label1.Text += ", " & zoneArray(0).ID

  End Sub

  Protected Sub Button4_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = "WebPartZone1 index:  " & mgr.Zones.IndexOf(WebPartZone1)

  End Sub

  Protected Sub Button5_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
    Label1.Text = String.Empty

    Dim zoneCollection As WebPartZoneCollection
 = mgr.Zones
    Dim zone As WebPartZone
    For Each zone In zoneCollection
      If zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
 Then
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar
      Else
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
      End If
    Next zone

  End Sub

End Class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webpartzonecollection_overview
 : System.Web.UI.Page
{

  protected void Button1_Click(object sender,
 EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = "WebPartZone Count:  " + mgr.Zones.Count;
  }

  protected void Button2_Click(object sender,
 EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString();
  }

  protected void Button3_Click(object sender,
 EventArgs e)
  {
    Label1.Text = String.Empty;
    WebPartZoneBase[] zoneArray = new WebPartZoneBase[mgr.Zones.Count];
    mgr.Zones.CopyTo(zoneArray, 0);
    Label1.Text = zoneArray[2].ID;
    Label1.Text += ", " + zoneArray[1].ID;
    Label1.Text += ", " + zoneArray[0].ID;
  }

  protected void Button4_Click(object sender,
 EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = "WebPartZone1 index:  " + mgr.Zones.IndexOf(WebPartZone1);
  }

  protected void Button5_Click(object sender,
 EventArgs e)
  {
    Label1.Text = String.Empty;

    WebPartZoneCollection zoneCollection = mgr.Zones;
    foreach (WebPartZone zone in zoneCollection)
    {

      if (zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu)
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
      else
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
    }
  }
}

ブラウザでページを読み込みます。3 つの WebPartZone ゾーンが、格納しているサーバー コントロールと共に表示されます。ページの下部には、複数のボタンがあり、それぞれが WebPartZoneCollection オブジェクトを使用する動作をデモンストレーションします。各ボタンをクリックして、ゾーンとその内容に対する効果を確認します。WebPartZoneCollection オブジェクトのいくつかの側面を示す各ボタンに関連付けられたコードを表示するには、上記のこのコード例の 2 番目の部分として参照される部分クラス ファイルのコードを表示します。

.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.Collections.ReadOnlyCollectionBase
    System.Web.UI.WebControls.WebParts.WebPartZoneCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebPartZoneCollection メンバ
System.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ
その他の技術情報
ASP.NET Web パーツ ページ

WebPartZoneCollection コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

WebPartZoneCollection クラスの空のインスタンスを初期化します。

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As New WebPartZoneCollection
public WebPartZoneCollection ()
public:
WebPartZoneCollection ()
public WebPartZoneCollection ()
public function WebPartZoneCollection ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebPartZoneCollection コンストラクタ (ICollection)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

WebPartZoneCollection クラスのインスタンスを、WebPartZone オブジェクトのコレクションを渡すことによって初期化します。

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    webPartZones As ICollection _
)
Dim webPartZones As ICollection

Dim instance As New WebPartZoneCollection(webPartZones)
public WebPartZoneCollection (
    ICollection webPartZones
)
public:
WebPartZoneCollection (
    ICollection^ webPartZones
)
public WebPartZoneCollection (
    ICollection webPartZones
)
public function WebPartZoneCollection (
    webPartZones : ICollection
)

パラメータ

webPartZones

WebPartZone オブジェクトの ICollection。

例外例外
例外の種類条件

ArgumentNullException

ゾーンのコレクションは null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

WebPartZoneCollection コンストラクタの使用方法を次のコード例に示します。この例の完全なコードは、WebPartZoneCollection の概要にある「例」のセクションを参照してください。

コードの次のセクションでは、Zones プロパティの値を取得することによって、WebPartZoneCollection オブジェクトを変数に割り当てています。必要な場合は、Zones プロパティからすべてのゾーンを割り当てるのではなく、ページのすべてのゾーンのサブセットを格納する WebPartZoneBase オブジェクトの配列を作成し、その配列を新しい WebPartZoneCollection オブジェクトに割り当てることができます。

Protected Sub Button5_Click(ByVal
 sender As Object, ByVal
 e As EventArgs)
  Label1.Text = String.Empty

  Dim zoneCollection As WebPartZoneCollection
 = mgr.Zones
  Dim zone As WebPartZone
  For Each zone In zoneCollection
    If zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
 Then
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar
    Else
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
    End If
  Next zone

End Sub
protected void Button5_Click(object sender,
 EventArgs e)
{
  Label1.Text = String.Empty;

  WebPartZoneCollection zoneCollection = mgr.Zones;
  foreach (WebPartZone zone in zoneCollection)
  {

    if (zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu)
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
    else
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
  }
}

コレクションを作成した後は、コレクションを反復処理して、格納されているすべてのゾーンまたはその内容に対して操作を実行できます。プログラム例を実行するには、ブラウザにページを読み込み、各ゾーンの [Toggle Verb Render Mode] ボタンをクリックします。これによって、ゾーン内の各サーバー コントロールのタイトル バーの動詞の表示方法が変更されます。動詞は、ドロップダウン メニューに、またはタイトル バーに直接リンクとして表示できます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebPartZoneCollection クラス
WebPartZoneCollection メンバ
System.Web.UI.WebControls.WebParts 名前空間
その他の技術情報
ASP.NET Web パーツ ページ

WebPartZoneCollection コンストラクタ

WebPartZoneCollection クラスの新しいインスタンスを初期化します。

WebPartZoneCollection コンストラクタは、WebPartManager コントロール、Web パーツ コントロール セット内の他のコントロール、またはカスタムの開発者のコードによって、Web パーツ ページ上に存在する WebPartZone コントロールの読み取り専用のコレクションを作成するために使用されます。

ASP.NET Web パーツ ページ
オーバーロードの一覧オーバーロードの一覧
名前 説明
WebPartZoneCollection () WebPartZoneCollection クラスの空のインスタンスを初期化します。
WebPartZoneCollection (ICollection) WebPartZoneCollection クラスのインスタンスを、WebPartZone オブジェクトのコレクションを渡すことによって初期化します。
参照参照

関連項目

WebPartZoneCollection クラス
WebPartZoneCollection メンバ
System.Web.UI.WebControls.WebParts 名前空間

その他の技術情報

ASP.NET Web パーツ ページ
ASP.NET Web パーツ ページ

WebPartZoneCollection プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ InnerList  ReadOnlyCollectionBase インスタンスに格納されている要素のリストを取得します。 ( ReadOnlyCollectionBase から継承されます。)
参照参照

関連項目

WebPartZoneCollection クラス
System.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ

その他の技術情報

ASP.NET Web パーツ ページ

WebPartZoneCollection メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebPartZoneCollection クラス
System.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ

その他の技術情報

ASP.NET Web パーツ ページ

WebPartZoneCollection メンバ

WebPartZone コントロールの読み取り専用のコレクションを含みます。

WebPartZoneCollection データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド WebPartZoneCollection オーバーロードされます。 WebPartZoneCollection クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ InnerList  ReadOnlyCollectionBase インスタンスに格納されている要素のリストを取得します。(ReadOnlyCollectionBase から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebPartZoneCollection クラス
System.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ

その他の技術情報

ASP.NET Web パーツ ページ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「WebPartZoneCollection」の関連用語

WebPartZoneCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebPartZoneCollectionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS