Redigera

Dela via


WebPartManager.DisplayMode Property

Definition

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

public:
 virtual property System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ DisplayMode { System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ get(); void set(System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ value); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.WebParts.WebPartDisplayMode DisplayMode { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DisplayMode : System.Web.UI.WebControls.WebParts.WebPartDisplayMode with get, set
Public Overridable Property DisplayMode As WebPartDisplayMode

Property Value

A WebPartDisplayMode that determines a page's display mode.

Attributes

Exceptions

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.

Examples

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

Note

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>
<%@ Page Language="VB" %>

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

  
  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    mgr.DisplayMode = WebPartManager.BrowseDisplayMode
  End Sub
  
  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    mgr.DisplayMode = WebPartManager.DesignDisplayMode
  End Sub
  
  Protected Sub Button3_Click(ByVal sender As Object, _
  ByVal e As EventArgs)
    mgr.DisplayMode = WebPartManager.EditDisplayMode
  End Sub
  
</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>

Remarks

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.

Applies to

See also