Export (0) Print
Expand All

WebPartManager.DisplayMode Property

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)

[BrowsableAttribute(false)]
public virtual WebPartDisplayMode DisplayMode { get; set; }
<asp:WebPartManager DisplayMode="WebPartDisplayMode" />

Property Value

Type: System.Web.UI.WebControls.WebParts.WebPartDisplayMode
A WebPartDisplayMode that determines a page's display mode.

ExceptionCondition
ArgumentNullException

The WebPartDisplayMode object being assigned to the property is null.

ArgumentException

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.

TopicLocation
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).

NoteNote

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"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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;
  }

</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="mgr" 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>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart runat="server" ID="Appearance1">
          </asp:AppearanceEditorPart>
          <asp:LayoutEditorPart runat="server" ID="Layout1">
          </asp:LayoutEditorPart>
        </ZoneTemplate>
      </asp:EditorZone>
      <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"/>
    </div>
    </form>
</body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft