WebPartManager.EditDisplayMode Field


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

Represents the display mode in which end users can edit and modify server controls. This field is read-only.

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

public static readonly WebPartDisplayMode EditDisplayMode

The EditDisplayMode field references a custom WebPartDisplayMode object that is created and contained by the WebPartManager control. Because this is a static object, you can refer to it directly through the WebPartManager class without needing an instance of the control.

When a page that contains Web Parts controls first loads, it is in BrowseDisplayMode (browse mode) by default. When users want to edit or modify a server control, they must first switch the page to EditDisplayMode (edit mode). Second, they must select a specific server control to edit, by clicking the edit verb on the verbs menu in that control's header. After the control is in edit mode, the editing user interface (UI) appears for editing the selected control.

To enable edit mode on a page, the page must contain at least one EditorZone zone that includes one or more of the provided editing controls, such as the LayoutEditorPart control, or custom editing controls.

The following code example demonstrates how to work with the EditDisplayMode field programmatically. The code populates a drop-down list with the supported display modes for the page, which in this case are browse, design, and edit. To support editing, an <asp:EditorZone> element is in the page. Notice that, in the Page_PreRender method, the code checks whether the current DisplayMode property is set to EditDisplayMode. If so, Label1 will be visible, and if not, Label1 will be hidden.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  protected void Page_Init(object sender, EventArgs e)
    foreach (WebPartDisplayMode mode in mgr.SupportedDisplayModes)
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr))
        ListItem item = new ListItem(modeName, modeName);

  protected void DisplayModeDropdown_SelectedIndexChanged(object 
    sender, EventArgs e)
    String selectedMode = DisplayModeDropdown.SelectedValue;
    WebPartDisplayMode mode = 
    if (mode != null)
      mgr.DisplayMode = mode;

  protected void Page_PreRender(object sender, EventArgs e)
    if (mgr.DisplayMode == WebPartManager.EditDisplayMode)
      Label1.Visible = true;
      Label1.Visible = false;


<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">
            <asp:ListItem Value="http://www.msn.com">
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
      <asp:EditorZone ID="EditorZone1" runat="server">
          <asp:AppearanceEditorPart runat="server" 
          <asp:LayoutEditorPart runat="server" ID="Layout1">
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Edit Mode" 
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" runat="server" 

After you load the page in a browser, you are in browse mode by default. Notice the label on the page is hidden. Use the drop-down list control to switch the page to edit mode. Notice that, because of the code in the Page_PreRender method, the label is now visible. Click the Edit verb in the verbs menu on one of the controls, to enable editing of that specific control.

.NET Framework
Available since 2.0
Return to top