WebPartZoneCollection Class
Assembly: System.Web (in system.web.dll)
The WebPartZoneCollection class contains the collection of WebPartZone controls that exist on a Web Parts page. It is used primarily by the WebPartManager control to track and manage all the zones. The WebPartManager control keeps a reference to the collection of zones on a page in its read-only Zones property.
The WebPartZoneCollection class is useful when you want to carry out operations on multiple zones or their contents at the same time, or when you need to locate a particular zone and examine or change its contents. Although the collection of zones itself is read-only and you cannot change the size of the collection object itself, you can still get references to the individual zones within the collection, and when you have a reference to an individual zone object, you can change its property values.
The WebPartZoneCollection class has two constructors. The first one, WebPartZoneCollection, simply initializes an empty instance of a new WebPartZoneCollection. The second one, WebPartZoneCollection(ICollection), initializes a collection by passing in an existing collection of zones.
The WebPartZoneCollection class contains an Item property. This property allows you to locate a WebPartZone control within the collection by passing in a string identifier. The zone is located by matching the string identifier to the value of the ID property on a WebPartZoneBase zone.
The WebPartZoneCollection class also has several methods that are useful for examining or accessing its contents. The Contains method determines whether a particular zone exists in the collection. The CopyTo method copies the collection to an array of WebPartZoneBase objects. Finally, the IndexOf method returns the index of a particular zone within the collection.
The following code example demonstrates the use of the WebPartZoneCollection class. The code example contains three parts: two sections of code, and an explanation of how to run the example.
The first part of the code example is a Web page that contains three WebPartZone controls, each of which contains a single server control. Although these server controls are all standard ASP.NET controls, they can act as WebPart controls at run time because they are placed within a WebPartZone zone.
The second part of the code example is the partial class that contains the code to demonstrate usage of the WebPartZoneCollection class. This code handles the events for the Web page.
Load the page in a browser. The three WebPartZone zones are visible with their contained server controls. Near the bottom of the page are several buttons, each of which demonstrates some aspect of working with the WebPartZoneCollection object. Click each button to see its effect on the zones and their contents. To view the code associated with each button that demonstrates some aspect of the WebPartZoneCollection object, view the code in the partial class file referenced above as the second part of this code example.
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
System.Collections.ReadOnlyCollectionBase
System.Web.UI.WebControls.WebParts.WebPartZoneCollection
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.