O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 web parts commonly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required