WebPartManager.DisplayMode Property

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

Gets or sets the active display mode for a Web page that contains Web Parts controls.

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

public virtual WebPartDisplayMode DisplayMode { get; set; }
/** @property */
public WebPartDisplayMode get_DisplayMode ()

/** @property */
public void set_DisplayMode (WebPartDisplayMode value)

public function get DisplayMode () : WebPartDisplayMode

public function set DisplayMode (value : WebPartDisplayMode)

Property Value

A WebPartDisplayMode that determines a page's display mode.

Exception typeCondition


The WebPartDisplayMode object being assigned to the property is a null reference (Nothing in Visual Basic).


The WebPartDisplayMode object being assigned to the property is not one of the supported display modes.

- or -

The WebPartDisplayMode object being assigned to the property is disabled.

A page that contains Web Parts controls is always in one of several possible display modes. For details about display modes, see Web Parts Page Display Modes.

The WebPartManager class creates the display modes for a Web page. Using the base WebPartDisplayMode class, the WebPartManager control creates several standard display mode objects that can be used on pages that contain Web Parts controls. These standard display modes are described in the WebPartDisplayMode class overview.

The WebPartManager control also manages the display modes for pages that use Web Parts controls. Using the DisplayMode property, the WebPartManager control keeps a reference to the current display mode on a page. You can also use the DisplayMode property to switch a page into different display modes. For an example of changing display modes on a page that uses Web Parts controls, see Walkthrough: Changing Display Modes on a Web Parts Page.

As part of managing the display mode, the WebPartManager control also provides events and event handlers relating to display modes, such as the OnDisplayModeChanged method and the OnDisplayModeChanging method. These methods provide a mechanism for customizing a page's behavior, and even for adding a custom display mode.

How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications
How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications

The following code example demonstrates programmatic use of the DisplayMode property. After loading the page in a browser, you can use the buttons near the bottom of the page to switch display modes. The page is in browse mode by default when it loads. If you switch to design mode, you can drag the server controls from one zone to another, or arrange two controls within one zone. If you switch to edit mode, you can click the verbs menu in the header of either of the server controls, select Edit, and edit the control using the provided editing user interface (UI).


Switching among display modes in a Web Parts application is very common, and you might want to provide a consistent, reusable way to do this on all your pages that contain Web Parts controls. For an example of a user control that changes display modes and that can be reused on many pages, see Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ Page Language="C#" %>

<script runat="server">
  protected void Button1_Click(object sender, EventArgs e)
    mgr.DisplayMode = WebPartManager.BrowseDisplayMode;

  protected void Button2_Click(object sender, EventArgs e)
    mgr.DisplayMode = WebPartManager.DesignDisplayMode;

  protected void Button3_Click(object sender, EventArgs e)
    mgr.DisplayMode = WebPartManager.EditDisplayMode;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <form id="form1" runat="server">
      <asp:WebPartManager ID="mgr" runat="server">
      <asp:WebPartZone ID="WebPartZone1" runat="server">
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
      <asp:WebPartZone ID="WebPartZone2" runat="server">
            Title="My Links">
            <asp:ListItem Value="http://www.microsoft.com">Microsoft</asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">MSN</asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">Contoso Corp.</asp:ListItem>
      <asp:EditorZone ID="EditorZone1" runat="server">
          <asp:AppearanceEditorPart runat="server" ID="Appearance1">
          <asp:LayoutEditorPart runat="server" ID="Layout1">
      <hr />
      <asp:Button ID="Button1" runat="server" Text="Browse Mode" OnClick="Button1_Click" />
      <br />
      <asp:Button ID="Button2" runat="server" Text="Design Mode" OnClick="Button2_Click"/>
      <br />
      <asp:Button ID="Button3" runat="server" Text="Edit Mode" OnClick="Button3_Click"/>

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

Community Additions