WebPartManager.DisplayMode Property


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

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 Value

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

A WebPartDisplayMode that determines a page's display mode.

Exception Condition

The WebPartDisplayMode object being assigned to the property is null.


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.

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#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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">
    <title>ASP.NET Example</title>
    <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"/>

.NET Framework
Available since 2.0
Return to top