Export (0) Print
Expand All

WebPartManager.CatalogDisplayMode Field

Represents the display mode used for adding server controls from a catalog of controls to a Web page. This field is read-only.

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

public static readonly WebPartDisplayMode CatalogDisplayMode

The CatalogDisplayMode 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 users want to add controls to a page, if a catalog of server controls is available, they can switch the page to CatalogDisplayMode (catalog mode), and the catalog user interface (UI) appears. The UI for a Web Parts catalog is provided by a CatalogZoneBase zone control. Developers add this zone to the page at design time, and then add server controls to the zone, so that users will be able to add those controls to their pages at run time. After the developer has added these controls, catalog mode becomes a supported display mode on the page because the necessary controls are there to enable catalog mode.

When a user switches a page to catalog mode, the zone and all the server controls that were added to it become visible, and the user can select controls from the catalog to add to the page, or remove controls from the page. After the controls have been added to the page, they appear in normal browse mode and the page is updated.

The following code example demonstrates how to work with the CatalogDisplayMode 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 catalog. The catalog mode is available because of the <asp:CatalogZone> element and its child elements in the Web page. Notice that, in the Page_PreRender method, the code checks whether the current DisplayMode property is set to CatalogDisplayMode. 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"
    "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 mgr.SupportedDisplayModes)
    {
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }      
    }
  }

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

  protected void Page_PreRender(object sender, EventArgs e)
  {
    if (mgr.DisplayMode == WebPartManager.CatalogDisplayMode)
      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="mgr" runat="server">
      </asp:WebPartManager>
      <asp:WebPartZone ID="WebPartZone1" 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:WebPartZone ID="WebPartZone2" runat="server" />
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart 
            ID="DeclarativeCatalogPart1" 
            runat="server">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" />             
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Catalog 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 that the label on the page is hidden. Use the drop-down list control to switch the page to catalog mode. Notice that, because of the code in the Page_PreRender method, the label is now visible. You can select the control in the catalog and add it to either of the two zones on the page.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft