Introduction to CatalogPart Controls...

Web parts can be dragged around, closed, minimized, edited at runtime, and cataloged, all requiring no coding effort on the part of the developer.


By: Brian Mains Date: November 27, 2004 Download the code.

If you've read my other articles on the web parts framework, you're probably beginning to see how extensive the framework can be. Web parts can be dragged around, closed, minimized, edited at runtime, and cataloged, all requiring no coding effort on part of the developer. This article will continue with the new features of the .NET framework by discussing the CatalogPart controls. This is another type of ASP.NET server control in the 2.0 framework.

Web parts have verbs, which are actions that can be performed on the web part. Each web part has an associated number of verbs that are enabled or disabled by default. Each web part can have a custom web verb added to it for additional, customized functionality. Specifically in all of the web verbs, the CatalogPart controls are directly involved with the “close” verb. When this verb is clicked, the web part is removed from the zone. Without a catalog, this closure would seem permanent; however, in previous examples that was because the last part of this puzzle was left out.

The PageCatalogPart is a container for all of the web parts that were closed by the user. The collection capabilities occur by default; no coding is needed for this to happen. That is what makes this framework so amazing; the reduction of overall coding effort. By clicking on this catalog, checking the appropriate checkbox, and selecting the appropriate zone, the web part is now active within the application, and everything is back to normal.

For controls that aren't common to the user’s activities, but may want to be retained as added functionality to an application, the DeclarativeCatalogPart may be used. Any controls that don’t want to be present on screen as the default can be defined in this catalog. All controls defined in this catalog retain in the catalog until the user chooses to move it to a web part zone. The method in moving it to the zone is the same as described previously.

If you have a file with a *.webpart extension, then the web part can be imported into the application. This is only supported if you have an ImportCatalogPart control. This control will import the new web part directly into the application at runtime. This catalog part will not be discussed in this article.

As with all of the web parts, each web part is grouped into a zone. The web part can only exist in a zone that accepts its type of web part. For example, a web part zone can only have web parts, an editor part zone can only have editor parts, and finally, a catalog zone can only have catalog parts. When a catalog zone is in the web form, a new option exists in the WebPartPageMenu control, titled "Add Web Parts to this Page". All available catalog parts are shown in the catalog zone. To exit out of the cataloging mode, click the close button in the upper-right corner. Let's take a look at the declaration of these controls. Below is the HTML code for the PageCatalogPart and the DeclarativeCatalogPart, residing in a catalog zone:

<asp:CatalogZone ID="CatalogZone1" Runat="server">
  <ZoneTemplate>
    <asp:DeclarativeCatalogPart Runat="server" ID="DeclarativeCatalogPart1">
      <WebPartsTemplate>
        <asp:BulletedList ID="list1" Runat="server">
          <asp:ListItem Value="1">First item</asp:ListItem>
          <asp:ListItem Value="2">Second item</asp:ListItem>
          <asp:ListItem Value="3">Third item</asp:ListItem>
        </asp:BulletedList>
      </WebPartsTemplate>
    </asp:DeclarativeCatalogPart>
    <asp:PageCatalogPart Runat="server" ID="PageCatalogPart1" />
  </ZoneTemplate>
</asp:CatalogZone>

Notice that the DeclarativeCatalogPart control declared one web part (a BulletedList control) that can be added to any available web part zones. The PageCatalogPart control contains all of the web parts that were "closed" in one of the web part zones; that is, the close verb button for the web part was clicked for a particular web part. Notice, though, that no code is required for this to automatically capture all of the closed parts.

Notice that only one catalog is shown at a time. By clicking on the appropriate catalog, all of the web parts stored in the catalog are shown. In the screen shot, note that the web part is called "Untitled". This occurs when there is no value provided for the Title property, or any standard .NET server control is used as a web part. That is something to keep in mind when using the web parts framework. This example is only an introduction of catalog parts. More articles on web parts will come later.

You may download the code here.