Export (0) Print
Expand All
2 out of 8 rated this helpful - Rate this topic

WebPartZone Class

Note: This class is new in the .NET Framework version 2.0.

Serves as the primary control in the Web Parts control set for hosting WebPart controls on a Web page.

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

public class WebPartZone : WebPartZoneBase
public class WebPartZone extends WebPartZoneBase
public class WebPartZone extends WebPartZoneBase

In the Web Parts feature, a zone is a defined region on a Web page that contains Web Parts controls. The primary functions of a zone are to lay out the controls it contains, and to provide a common user interface (UI) for those controls. For general information about zones and how they are used in Web Parts applications, see the reference documentation for the base WebZone and WebPartZoneBase classes, and the topic entitled Web Parts Control Set Overview.

The special function of the WebPartZone control is to contain WebPart controls, which form the main UI of Web Parts applications. A WebPartZone control can be declared in persistence format on a Web page, enabling developers to use it as a template and to add other server controls within the <asp:webpartzone> element. Any type of server control, if added to a WebPartZone zone, can function as a WebPart control at run time. This is true regardless of whether the added control is a WebPart control, a user control, a custom control, or an ASP.NET control. For more information, see the topic for the GenericWebPart class.

Besides containing WebPart controls, a WebPartZone control also provides a common UI for the controls it contains. This common UI, known collectively as chrome, consists of the peripheral UI elements on all the controls, such as the border, title, header and footer, style characteristics, and verbs (UI actions that a user can carry out on a control, such as close or minimize).

The WebPartZone class derives most of its behavior from the base WebZone and WebPartZoneBase classes; it adds only one unique member, the ZoneTemplate property. This property references an ITemplate object, which is a template that allows page developers to define the controls in a zone statically by using a <zonetemplate> element in the declarative markup of an .aspx page.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

The following code example demonstrates the use of the WebPartZone control in a Web Parts page. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control.

The first part of the example shows a custom class that inherits from the WebPartZone class, and that sets two of the base zone properties in the constructor.

using System;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  public class MyWebPartZone : WebPartZone
  {
    public MyWebPartZone()
    {
      base.VerbButtonType = ButtonType.Button;
      base.CloseVerb.Enabled = false;
    }
  }
}

The second part of the example shows a page that contains the custom WebPartZone control. Notice that the page requires a special Register directive near the top of the page to reference the assembly that contains the custom zone. The page also contains an <asp:webpartmanager> element, which is required on every Web Parts page. The <cc1:MyWebPartZone> element, which represents the custom WebPartZone control, contains a standard ASP.NET Calendar control. Because it is contained within a WebPartZone zone, the Calendar control will be wrapped with a GenericWebPart control at run time, which enables it to act as a WebPart control.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="cc1" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="MyWebPartZoneCS" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="WebPartManager1" runat="server" />
      <cc1:MyWebPartZone ID="MyWebPartZone1" runat="server">
        <VerbStyle Font-Italic="true" />
        <PartChromeStyle BackColor="lightblue" />
        <PartStyle BackColor="gray" />
        <PartTitleStyle Font-Bold="true" />
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </cc1:MyWebPartZone>
    </div>
    </form>
</body>
</html>

Examine the declarative markup for the custom WebPartZone control. Notice that you can set various zone-level properties in the markup, as shown in the following code example.

NoteNote

It is very important to note the use of the <zonetemplate> element. This element, as described in the Remarks section, is required within a WebPartZone zone to wrap the static WebPart controls that are declared in a page.

<cc1:MyWebPartZone ID="MyWebPartZone1" runat="server">
  <VerbStyle Font-Italic="true" />
  <PartChromeStyle BackColor="lightblue" />
  <PartStyle BackColor="gray" />
  <PartTitleStyle Font-Bold="true" />
  <ZoneTemplate>
    <asp:Calendar ID="Calendar1" runat="server" 
      Title="My Calendar" />
  </ZoneTemplate>
</cc1:MyWebPartZone>

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 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.