WebPartManager.BrowseDisplayMode Field

Definition

Represents the default display mode for pages that contain Web Parts controls. This field is read-only.

C#
public static readonly System.Web.UI.WebControls.WebParts.WebPartDisplayMode BrowseDisplayMode;

Field Value

Examples

The following code example demonstrates how to work with the BrowseDisplayMode field programmatically. The code populates a drop-down list with the supported display modes, which in this case are browse and design. Notice that, in the Page_PreRender method, the code checks whether the current DisplayMode property is set to BrowseDisplayMode. If so, Label1 will be visible, and if not, Label1 will be hidden.

ASP.NET (C#)
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">


  protected void Page_Init(object sender, EventArgs e)
  {
    foreach (WebPartDisplayMode mode in mgr1.SupportedDisplayModes)
    {
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr1))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }      
    }
  }

  protected void DisplayModeDropdown_SelectedIndexChanged(object 
    sender, EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;
    WebPartDisplayMode mode = 
      mgr1.SupportedDisplayModes[selectedMode];
    if (mode != null)
      mgr1.DisplayMode = mode;
  }

  protected void Page_PreRender(object sender, EventArgs e)
  {
    if (mgr1.DisplayMode == WebPartManager.BrowseDisplayMode)
      Label1.Visible = true;
    else
      Label1.Visible = false;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" runat="server">
      </asp:WebPartManager>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            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:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Browse Mode" 
        Font-Bold="true"
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>

After you load the page in a browser, you are in browse mode by default. Notice the label on the page that indicates you are in browse mode. Use the drop-down list control to switch the page to design mode. Notice that, because of the code in the Page_PreRender method, the label is now hidden.

Remarks

The BrowseDisplayMode 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 are simply browsing as they would on a normal Web page, the page remains in browse mode. If users want to personalize a page's layout, controls, appearance, or behavior, they must switch the page into one of the specialized display modes available through the SupportedDisplayModes property.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also