This documentation is archived and is not being maintained.

WebPartZoneBase Class

Serves as the base class for all zone controls that act as containers for WebPart (or other server or user) controls.

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

<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public MustInherit Class WebPartZoneBase _
	Inherits WebZone _
	Implements IPostBackEventHandler
Dim instance As WebPartZoneBase
<asp:WebPartZoneBase />

In the Web Parts control set, a zone is a composite control, rendered as an HTML table, that contains other controls in a defined region of a Web page. The WebPartZoneBase class is a zone that inherits from the base WebZone class and provides a base set of behaviors for derived zones that contain WebPart controls, server controls, and user controls. The combination of WebPartZoneBase zones with WebPart (and other server) controls forms the primary UI of a Web Parts application, the normal view of a page that users interact with most of the time.

All zones provide a common set of UI elements for the controls they contain. For a detailed discussion of the UI elements common to all zones, see the class overview topic for the WebZone class. The WebPartZoneBase zone includes a body section that contains server controls, and an associated WebPartChrome object used for rendering the contained controls and their chrome elements, such as their verbs, borders, and so on.

In addition to the features inherited from the WebZone class, the WebPartZoneBase class adds client-side control dragging, specific verbs (to enable common UI actions such as minimizing, closing, deleting, and editing controls), and additional style features. The WebPartZoneBase class is also the class to inherit from if you want to design a custom zone that is database-driven. For example, you could create a custom weather Web Parts zone that inherits from WebPartZoneBase, and is designed to contain and provide layout features and other services for WebPart controls that are data-bound and display weather information.

The WebPartZoneBase class contains a number of properties for working with style attributes in a zone. There are several properties for borders, including BorderStyle and BorderWidth. There is a group of properties for working with style attributes of menus that can appear in the header of a zone, such as MenuLabelStyle, MenuVerbStyle, and others.

The WebPartZoneBase class also contains a number of members for handling verbs in a zone. These members relate to the verbs that appear on the part controls in the zone. While zone-level verbs can be added to WebPartZoneBase zones, by default they do not have any. There is a set of standard verbs provided with the Web Parts control set for use with part controls, and developers can add custom verbs as well. Some important properties for working with verbs include properties that reference some of the standard verb objects, such as CloseVerb, ConnectVerb, DeleteVerb, and EditVerb, HelpVerb, and MinimizeVerb. The standard verbs appear on a verbs menu (typically presented in the UI as a drop-down menu) in the title bar of each control contained in a zone. There is also a VerbButtonType property that allows you to determine what type of clickable object represents a verb in the UI.

Other key members for working with verbs include the OnCreateVerbs method, which is an event handler that can be overridden for custom handling of the verb creation process, and the CreateVerbs event.

The WebPartZoneBase class contains a number of members for working with WebPart controls contained within a zone. The WebParts property references the collection of all WebPart (and other server) controls in the zone. Several methods correspond to the standard verbs or actions that a user can carry out on WebPart controls in a zone, such as CloseWebPart, ConnectWebPart, and EditWebPart.

There are also a number of members in the WebPartZoneBase class that concern how the WebPart controls are laid out or arranged within the zone. The AllowLayoutChange property determines whether controls can be moved among zones or rearranged within a zone by users. The LayoutOrientation property allows you to determine whether the controls in a zone are arranged horizontally or vertically.


Internet Explorer might render the height of a WebPartZone or its contained controls in an unexpected way, depending on the orientation of the zone. For more details, see the documentation for the LayoutOrientation or the Height properties.

Other methods in the WebPartZoneBase class provide you with detailed programmatic control over the rendering of the various areas of a zone. Many of these methods override the base methods inherited from the WebZone class, to customize the rendering for zones that contain WebPart controls. Important methods include Render, RenderBody, RenderDropCue, and RenderHeader.

The following code example demonstrates the use of the WebPartZoneBase class. The code shows how a derived class, WebPartZone, is used declaratively in a Web Parts page to contain WebPart controls. The code example has four sections: the first three sections describe the code files, and the fourth explains how to run the code.

The first part of the code example is a user control that enables users to switch the page into different display modes. For more information on Web Parts display modes and a description of the code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ control language="vb" classname="DisplayModeMenuVB"%>
<script runat="server">
  ' Use a field to reference the current WebPartManager. 
  Dim _manager As WebPartManager

  Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler Page.InitComplete, AddressOf InitComplete
  End Sub 

  Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs)
    _manager = WebPartManager.GetCurrentWebPartManager(Page)

    Dim browseModeName As String = WebPartManager.BrowseDisplayMode.Name

    ' Fill the dropdown with the names of supported display modes. 
    Dim mode As WebPartDisplayMode
    For Each mode In _manager.SupportedDisplayModes
      Dim modeName As String = mode.Name
      ' Make sure a mode is enabled before adding it. 
      If mode.IsEnabled(_manager) Then 
        Dim item As New ListItem(modeName, modeName)
      End If 
    Next mode

    ' If shared scope is allowed for this user, display the scope-switching 
    ' UI and select the appropriate radio button for the current user scope. 
    If _manager.Personalization.CanEnterSharedScope Then
      Panel2.Visible = True 
      If _manager.Personalization.Scope = PersonalizationScope.User Then
        RadioButton1.Checked = True 
        RadioButton2.Checked = True 
      End If 
    End If 

  End Sub 

  ' Change the page to the selected display mode. 
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs)

    Dim selectedMode As String = DisplayModeDropdown.SelectedValue   
    Dim mode As WebPartDisplayMode = _
    If Not (mode Is Nothing) Then
      _manager.DisplayMode = mode
    End If 

  End Sub 

  ' Set the selected item equal to the current display mode. 
  Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    Dim items As ListItemCollection = DisplayModeDropdown.Items
    Dim selectedIndex As Integer = _
    DisplayModeDropdown.SelectedIndex = selectedIndex

  End Sub 

  ' Reset all of a user's personalization data for the page. 
  Protected Sub LinkButton1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)


  End Sub 

  ' If not in User personalization scope, toggle into it. 
  Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)

    If _manager.Personalization.Scope = PersonalizationScope.Shared Then
    End If 

  End Sub 

  ' If not in Shared scope, and if user is allowed, toggle the scope. 
  Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)

    If _manager.Personalization.CanEnterSharedScope AndAlso _
      _manager.Personalization.Scope = PersonalizationScope.User Then
    End If 

  End Sub

  <asp:Panel ID="Panel1" runat="server" 
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text="&nbsp;Display Mode" 
      Width="120" />
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"  
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for the page."
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />

The second part of the code example is a code-beside file that contains the code to handle events for the main Web page. The code in this file shows how to work with some of the key WebPartZoneBase members programmatically.

Imports System
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Partial Public Class WebPartZoneBase_overview

  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As [Object], ByVal e As EventArgs) 
    Label1.Text = DateTime.Now.ToLongDateString()
    Label2.Text = String.Empty
  End Sub 

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    If WebPartZone2.VerbButtonType = ButtonType.Button Then
        WebPartZone2.VerbButtonType = ButtonType.Link
        WebPartZone2.VerbButtonType = ButtonType.Button
    End If 
  End Sub 

  Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) 
    If WebPartZone1.LayoutOrientation = Orientation.Vertical Then
        WebPartZone1.LayoutOrientation = Orientation.Horizontal
        WebPartZone1.LayoutOrientation = Orientation.Vertical
    End If
    Page_Load(sender, e)
  End Sub  

  Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim builder As New StringBuilder()
    builder.AppendLine("<strong>WebPartZone2 WebPart IDs</strong><br />")
    Dim part As WebPart
    For Each part In  WebPartZone1.WebParts
      builder.AppendLine("ID: " + part.ID + "; Type: " _
                          + part.GetType().ToString() _
                          + "<br />")
    Next part
    Label2.Text = builder.ToString()
    Label2.Visible = True 
  End Sub  

  Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim builder As New StringBuilder()
    builder.AppendLine("<strong>WebPartZone1 DisplayTitle Property</strong><br />")
    builder.AppendLine(WebPartZone1.DisplayTitle + "<br />")
    Label2.Text = builder.ToString()
    Label2.Visible = True 
  End Sub 

End Class

The third part of the code example is the Web page that contains the WebPartZone controls that exhibit behavior from the base WebPartZoneBase class, and WebPart controls contained in the zones.

<%@ Page Language="VB" 
  Inherits="WebPartZoneBase_overview"  %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModeMenuVB.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
<head id="Head1" runat="server">
    <title>WebPartZoneBase Example</title>
    <form id="form1" runat="server">
      <asp:WebPartManager ID="WebPartManager1" Runat="server" />
      <uc1:DisplayModeMenuVB ID="DisplayModeMenu1" runat="server" />
      <table width="75%">
              LayoutOrientation="Vertical" >
              <EditVerb Text="Edit WebPart" />
              <SelectedPartChromeStyle BackColor="LightBlue" />
                  Title="Favorite Links" >
                  <asp:ListItem Value="">
                  <asp:ListItem Value="">
                  <asp:ListItem Value="">
                <asp:Calendar ID="Calendar1" Runat="server" 
                  Title="My Calendar" />
          <td valign="top" align="right">
              EmptyZoneText="Add WebParts to this empty Zone."
              MenuLabelText="Verbs Menu" 
              MenuPopupImageUrl="label.gif" >
              <VerbStyle Font-Italic="true" />
              <MenuLabelStyle BackColor="Lime" BorderWidth="1"  />
              <MenuLabelHoverStyle Font-Bold="true" />
              <MenuVerbHoverStyle BackColor="LightGrey" />
              <MenuVerbStyle Font-Italic="true" /> 
                <asp:Label ID="Label1" Runat="server" Title="Date" />
            <asp:EditorZone ID="EditorZone1" Runat="server">
                <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
                  Runat="server" />
                <asp:LayoutEditorPart ID="LayoutEditorPart1" 
                  Runat="server" />
    <asp:Button ID="Button1" Runat="server" 
      Width="200" Text="Toggle WebPartZone2 Buttons" 
      OnClick="Button1_Click" />
    <br />
    <asp:Button ID="Button2" Runat="server" 
      Width="200"  Text="Toggle Layout Orientation" 
      OnClick="Button2_Click" />
    <br />
    <asp:Button ID="Button3" Runat="server" 
      Width="200" Text="List WebPartZone1 WebParts" 
      OnClick="Button3_Click" />
    <br />
    <asp:Button ID="Button4" Runat="server" 
      Width="200" Text="WebPartZone1 Display Title" 
      OnClick="Button4_Click" />
    <br />
    <asp:Label ID="Label2" Runat="server" Visible="false" />

Load the Web page in a browser. Use the Display Mode drop-down list control to switch the page into design mode, click the WebPart controls, and try dragging them between the visible zones. Click some of the buttons on the page to see the effect of using various members of the WebPartZoneBase class. Next, switch the page to edit mode. Make sure a WebPart control is positioned in WebPartZone2, click the verbs menu on the control's title bar, and click Edit to edit the control. Finish editing that control, and then edit one of the controls in the other zone. As you carry out these steps, notice the differences in the UI styles of the controls and the zones, which are the effect of using the various members of the WebPartZoneBase class.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0