WebPartChrome Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Enables developers to override the rendering for only the selected sections of WebPart or server controls in a WebPartZoneBase zone.

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


public class WebPartChrome

System_CAPS_pubmethodWebPartChrome(WebPartZoneBase, WebPartManager)

Initializes a new instance of the control.


Gets a value that indicates whether controls can be dragged into and out of the zone.


Gets a reference to the current WebPartManager instance.


Gets a reference to the associated WebPartZoneBase zone.

System_CAPS_protmethodCreateWebPartChromeStyle(WebPart, PartChromeType)

Creates the style object that supplies style attributes for each WebPart control rendered by the WebPartChrome object.


Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFilterWebPartVerbs(WebPartVerbCollection, WebPart)

Excludes specific verbs from being rendered, based on criteria provided by a developer.


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Gets the client ID for the WebPartChrome object as rendered in a Web page.


Gets the client ID for the table cell that contains the title for a WebPart control.


Gets a collection of verbs that should be rendered with a WebPart control.


Creates a shallow copy of the current Object.(Inherited from Object.)


Performs tasks that must be done prior to rendering WebPart controls.

System_CAPS_protmethodRenderPartContents(HtmlTextWriter, WebPart)

Renders the main content area of a WebPart control, excluding the header and footer.

System_CAPS_pubmethodRenderWebPart(HtmlTextWriter, WebPart)

Renders a complete WebPart control with all its sections.


Returns a string that represents the current object.(Inherited from Object.)

Web Parts chrome refers to the peripheral user interface (UI) elements that frame each WebPart control or server control contained in a WebPartZoneBase zone. The chrome for a control includes its border, its title bar, and the icons, title text, and verbs menu that appear within the title bar. The appearance of the chrome is set at the zone level, and applies to all the server controls in the zone.

The Web Parts control set uses the WebPartChrome class to render the chrome for WebPart controls. Additionally, this class provides a way for developers to customize the rendering of any individual section (such as the header or footer) of the WebPart controls in a WebPartZoneBase zone without having to handle all the rendering for those controls. For example, you can override the CreateWebPartChromeStyle method to customize some specific style attributes applied to the WebPartZoneBase zone, but you can rely on the default rendering to handle the rest.

The WebPartChrome class contains several important methods that are useful when you want to override the rendering of WebPart controls. One is the CreateWebPartChromeStyle method, which enables you to change the style attributes of the Style object associated with the WebPartChrome object used to render a control. Another is the WebPartChrome constructor, which you use when you override the CreateWebPartChrome method in a custom WebPartZoneBase class to create an instance of your custom WebPartChrome object. Another useful method is the RenderPartContents method, which you can use to control the rendering of the content area of controls in a zone (as opposed to chrome elements such as headers, footers, and title bars). The GetWebPartVerbs method enables you to exclude certain verbs from being rendered, if for some reason you do not want users to see those verbs in the UI. Finally, if you want complete programmatic control over all aspects of rendering the WebPart controls, you can override the RenderWebPart method.

Several properties of the WebPartChrome class are also useful. The Zone and WebPartManager properties provide references to the zone associated with the WebPartChrome object and the current WebPartManager instance, respectively.

Notes to Inheritors:

Inherit from the WebPartChrome class when you want to override the default rendering of certain sections of WebPart or server controls. You can optionally override the CreateWebPartChromeStyle method, the GetWebPartVerbs method, and especially the RenderPartContents or RenderWebPart methods, to customize the rendering. To use your custom WebPartChrome class for the WebPart controls in a zone, develop a custom zone derived from the WebPartZoneBase class, and override its CreateWebPartChrome method. For details on how to use a child WebPartChrome object in a zone, see the Example section.

The following code example demonstrates how to use the WebPartChrome class to override the default rendering of WebPart controls in a WebPartZoneBase zone.

The code example has four parts:

  • A user control that enables you to change display modes on a Web Parts page.

  • A Web page that hosts all the controls in the example.

  • A class that contains the source code for a custom WebPartZoneBase zone and a WebPartChrome class.

  • An explanation of how the example works.

The first part of the code example is the user control. The source code for the user control comes from another topic. For this code example to work, you need to obtain the .ascx file for the user control from the Walkthrough: Changing Display Modes on a Web Parts Page topic, and place the file in the same folder as the .aspx page in this code example.

The second part of the example is the Web page. Note that there is a Register directive near the top of the file to register the compiled component and a tag prefix. Also note that the page references the custom zone using the element <aspSample:MyZone> and includes several standard ASP.NET server controls within the zone. The server controls do not implement any actual functionality; they are used here only to illustrate how the WebPartChrome class features apply to rendering zones. Note that these server controls, though they are not actual WebPart controls, are each automatically wrapped (by ASP.NET) with a GenericWebPart object at run time, so they will have the same functionality as WebPart controls.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc1" 
  Src="~/DisplayModeMenuCS.ascx" %>
<%@ Register TagPrefix="aspSample" 
  Assembly="MyChromeCS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <uc1:DisplayModeMenuCS id="menu1" runat="server" />
    <aspSample:MyZone ID="WebPartZone1" runat="server"
      <PartTitleStyle Font-Bold="true"
        <asp:Panel runat="server" id="panel1" 
          title="Vote on Issues" >
          <asp:RadioButtonList ID="RadioButtonList1" runat="server" >
            <asp:ListItem Value="1">Issue 1</asp:ListItem>
            <asp:ListItem Value="2">Issue 2</asp:ListItem>
            <asp:ListItem Value="3">Issue 3</asp:ListItem>
          <asp:Button ID="Button1" runat="server" Text="Cast Vote" />
        <asp:FileUpload ID="FileUpload1" runat="server" 
          title="Upload Files" />
    <asp:WebPartZone ID="WebPartZone2" runat="server" />
    <asp:EditorZone ID="EditorZone1" runat="server">
        <asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />

The third part of the code example is the source for the custom WebPartZoneBase zone and a WebPartChrome class. In the constructor for the custom zone class, the code checks the MyZone.RenderVerbsInMenu property. If the value is true, verbs are rendered in a menu for each of the WebPart controls in the zone. This is the normal, default behavior in the Web Parts controls set. If the MyZone.RenderVerbsInMenu property value is false, which is the default in this custom zone, the verbs are rendered individually as links in the title bar of each control. Notice that in the Web page code where the <aspSample:MyZone> element is declared, there is a RenderVerbsInMenu attribute set to true, so that the verbs will appear in menus on the controls. To experiment with this feature, you can set the declarative RenderVerbsInMenu attribute to false, and note how the verbs are rendered as links.

The custom WebPartChrome class overrides the rendering on several methods, and the custom zone creates an instance of the MyWebPartChrome class in its CreateWebPartChrome method. This applies the custom rendering to the 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 Web Server Control.

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
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
    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class MyZone : WebPartZone
    private Boolean _renderVerbsInMenu;

    protected override WebPartChrome CreateWebPartChrome()
      WebPartChrome theChrome = new MyWebPartChrome(this, 
      if (RenderVerbsInMenu)
        this.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
        this.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
      return theChrome;

    public Boolean RenderVerbsInMenu
      get { return _renderVerbsInMenu; }
      set { _renderVerbsInMenu = value; }

    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class MyWebPartChrome : WebPartChrome
    WebPartZoneBase theZone;
    WebPartManager theManager;

    public MyWebPartChrome(WebPartZoneBase aZone, WebPartManager aManager) : 
      base(aZone, aManager)
      theZone = aZone;
      theManager = aManager;

    protected override WebPartVerbCollection GetWebPartVerbs(WebPart webPart)
      ArrayList verbSet = new ArrayList();
      foreach (WebPartVerb verb in base.GetWebPartVerbs(webPart))
        if (verb.Text != "Close")
      WebPartVerbCollection reducedVerbSet = 
        new WebPartVerbCollection(verbSet);
      return reducedVerbSet;

    protected override Style CreateWebPartChromeStyle(WebPart part, 
      PartChromeType chromeType)
      Style finalStyle = new Style();
      finalStyle.CopyFrom(base.CreateWebPartChromeStyle(part, chromeType));
      finalStyle.Font.Name = "Verdana";
      return finalStyle;

    protected override void RenderPartContents(HtmlTextWriter writer, 
      WebPart part)

        if (part == this.WebPartManager.SelectedWebPart)
          HttpContext.Current.Response.Write("<span>Not rendered</span>");
          if(this.Zone.GetType() == typeof(MyZone))


When you load the Web page in a browser, you can see how the various stylistic and other rendering customizations made in the source code of the MyWebPartChrome class appear on the WebPart controls rendered in the zone.

.NET Framework
Available since 2.0

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

Return to top