11.2. Creating a Reusable Web Parts Catalog

Problem

You need to reuse the same set of web parts in many pages in your application but you want to avoid having to declare them on every page. Instead, you’d like to create a reusable web parts catalog you can maintain separately but make available to the pages.

Solution

Implement the solution described in Recipe 11.1, create a user control containing all of the web parts to be available in your pages, remove the <WebPartsTemplate> element and control definitions from the DeclarativeCatalogPart control, and set the WebPartsListUserControlPath attribute of the DeclarativeCatalogPart to the name of the user control you created.

In the .ascx file for the user control that will contain all available web parts, add the server controls, user controls, and custom web parts in the same manner you would add them to a .aspx file.

In the .aspx file:

  1. Remove the <WebPartsTemplate> element and control definitions from the DeclarativeCatalogPart control.

  2. Set the WebPartsListUserControlPath attribute of the DeclarativeCatalogPart to the name of the user control containing the available web parts.

The application we have implemented to demonstrate the solution is shown in Examples 11-8, 11-9, 11-10 through 11-11. Example 11-8 shows the user control used as a “web parts catalog.” Examples 11-9, 11-10 through 11-11 show the .aspx and code-behind for a page that demonstrates using the “web parts catalog” user control.

Discussion

Applications that use ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.