The following code example demonstrates how to set the CatalogIconImageUrl property for a WebPart control, so that an image appears with the control in a catalog of controls. This example assumes the use of a custom control, TextDisplayWebPart, created in the Example section of the WebPart class overview.

The code example also uses a custom user control that enables users to change display modes on a Web Parts page. The user control is referenced by means of a Register directive near the top of the Web page that hosts the user control. For a detailed description of how to create this user control and work with display modes, see Walkthrough: Developing and Using a Custom Web Server Control.

In the declarative markup of the Web page, note the <asp:CatalogZone> element. Nested within it are several elements, including an <aspSample:TextDisplayWebPart> element. This set of elements enables the custom WebPart control to appear in a catalog. In the markup for the <aspSample:TextDisplayWebPart> element, notice that the CatalogIconImageUrl attribute is assigned a string that contains the URL to an image file. Load the page in a browser and use the Display Mode drop-down list control to change the display mode to catalog mode. Then use the catalog user interface (UI) to add the custom WebPart control to the page.