Zone Property

WebPart.Zone Property


Gets the WebPartZoneBase zone that currently contains a WebPart control.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public WebPartZoneBase Zone { get; }

Property Value

Type: System.Web.UI.WebControls.WebParts.WebPartZoneBase

The WebPartZoneBase that currently contains a Web Parts control on a Web page. If a Web Parts control is currently closed on a page, the return value is null.

In the architecture of the Web Parts control set, controls can have Web Parts functionality only if they operate inside of WebPartZoneBase zones. The standard WebPartZoneBase zone to use on Web pages is the WebPartZone control. Although end users can move Web Parts controls between different zones on a Web page, a given instance of a control can reside in only one zone at a time. A Web Parts control, and its associated WebPartManager control, use the Zone property to keep track of which zone the control currently resides in, and what common layout and style characteristics of the zone apply to all contained Web Parts controls.

Legacy Code Example

The following code example demonstrates how to access the Zone and ZoneIndex properties for a custom Web Parts control. This example assumes the use of a custom control, TextDisplayWebPart, created in the Example section of the WebPart class overview.

The code example includes a custom user control that enables users to change display modes on a Web Parts page. The user control is referenced by means of a Register directive near the top of the Web page that hosts the user control. For a detailed description of how to create this user control and work with display modes, see Walkthrough: Developing and Using a Custom Web Server Control.

Code snippet is not found. Confirm that the code snippet name 'WebParts_WebPart_Zone' is correct.

The second part of the code example is the Web page. There are two <asp:webpartzone> elements on the page, each representing a Web Parts zone. The first zone contains a standard Calendar control, which acts like a WebPart control at run time because it is in a zone. The second zone contains the TextDisplayWebPart control. When a user clicks the Zone Information button, the Label1 control displays the values of the ZoneIndex property for the control, and the ID property of the zone that currently contains the control.

Code snippet is not found. Confirm that the code snippet name 'WebParts_WebPart_Zone' is correct.

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft