How to: Provide Optional Web Parts Controls

One feature of the Web Parts control set is the ability to make a catalog of optional controls available for an end user to add to a page.

Note

You must provide a way for end users to view the page in catalog mode so that they can see the catalog. You can do this by setting the DisplayMode property of the local WebPartManager instance to catalog mode, as described in How to: Set the Display Mode of a Web Parts Page. Alternatively, you can create a user control that exposes all available page display modes and provides other useful functionality. For more information, see Walkthrough: Changing Display Modes on a Web Parts Page.

To create a catalog of optional Web Parts controls

  1. Create an ASP.NET Web Parts page with personalization enabled. For details, see Walkthrough: Creating a Web Parts Page.

  2. Add to the page a WebPartZone zone that contains a ZoneTemplate template. This is where the user will put the controls he or she selects.

  3. Add to the page a CatalogZone zone that contains a ZoneTemplate template, which in turn contains a DeclarativeCatalogPart control.

  4. Inside the DeclarativeCatalogPart control, add a pair of <WebPartsTemplate> tags that contain the controls to include in your catalog. The markup for the CatalogZone zone should now look something like the following example.

    <asp:CatalogZone ID="CZ1" runat="server">
        <ZoneTemplate>
            <asp:DeclarativeCatalogPart ID="DCP1" runat="server">
                <WebPartsTemplate>
                    <asp:Label ID="Label1" runat="server" Text="Label" />
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </WebPartsTemplate>
            </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
    </asp:CatalogZone>
    
    <asp:CatalogZone ID="CZ1" runat="server">
        <ZoneTemplate>
            <asp:DeclarativeCatalogPart ID="DCP1" runat="server">
                <WebPartsTemplate>
                    <asp:Label ID="Label1" runat="server" Text="Label" />
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </WebPartsTemplate>
            </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
    </asp:CatalogZone>
    

    The controls inside the DeclarativeCatalogPart control will be available to the end user when the page is viewed in catalog mode.

See Also

Tasks

Walkthrough: Changing Display Modes on a Web Parts Page

How to: Set the Display Mode of a Web Parts Page

Reference

DeclarativeCatalogPart

CatalogZone

WebPartZone

WebPartManager.DisplayMode