ImportCatalogPart.GetAvailableWebPartDescriptions Method

Note: This method is new in the .NET Framework version 2.0.

Returns a collection of descriptions of the available WebPart controls in a catalog.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public:
virtual WebPartDescriptionCollection^ GetAvailableWebPartDescriptions () override
public WebPartDescriptionCollection GetAvailableWebPartDescriptions ()
public override function GetAvailableWebPartDescriptions () : WebPartDescriptionCollection

Return Value

A WebPartDescriptionCollection that contains a WebPartDescription for each control in a catalog.

The GetAvailableWebPartDescriptions method provides an implementation for the abstract base method declared in the CatalogPart class. The GetAvailableWebPartDescriptions method returns description information for each control in a catalog. Note that in the case of an ImportCatalogPart control, there can be only one server control in the catalog at a time, even though the method would work if there were multiple controls.

A WebPartDescription object is an object that contains essential information about a WebPart control, including its ID, an object reference to the control, and the values of several important properties that are inherited from the Part class, such as Title and Description.

The GetAvailableWebPartDescriptions method improves performance. When a catalog is created, it needs some information about each control it contains, including a title, a description, an icon (if one exists), and an ID. Rather than having to create an instance of each control to get this information, a CatalogZoneBase zone that creates a catalog calls the GetAvailableWebPartDescriptions method, and the call returns only the description information for the control rather than an instance of the control.

The following code example demonstrates how to use the GetAvailableWebPartDescriptions method on a Web page. The example has four parts:

  • A user control that enables you to change display modes on a Web Parts page.

  • A Web page that contains a CatalogZone control and an ImportCatalogPart control, along with code that uses the GetAvailableWebPartDescriptions method.

  • A source code file that contains two custom WebPart controls.

  • An explanation of how the example works when you load the page in a browser.

The first part of this code example is the user control that enables users to change display modes on a Web page. You should place the following source code in a file and name it Displaymodemenucs.ascx or Displaymodemenuvb.ascx (depending on which language you are using). For details about display modes and a description of the source code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.

No code example is currently available or this language may not be supported.

The second part of the code example is the Web page. At the top of the page are two register directives, one for the user control and one for the compiled component that contains the two custom WebPart controls. Both of these controls are referenced declaratively in the markup of the page. On the declarative references to the WebPart controls (both begin with an aspSample prefix), note that each has an exportMode="all" attribute added to it. This attribute enables you to export a .WebPart description file for the control, which you will use in a later to step to import the control to a page.

NoteNote

To enable users of a Web Parts application to export a description file for WebPart controls, you must also enable the export feature in the Web application by adding an enableExport="true" attribute to the <webParts> element (which is a child of the <system.web> element) in the Web.config file. Export is disabled by default, so if you have not yet enabled export for your application, edit the Web.config file and do it now.

The Web page also has a declarative reference to the ImportCatalogPart control, nested within the proper hierarchy of declarative elements. The GetAvailableWebPartDescriptions method is called within the code for the Button1_Click method.

No code example is currently available or this language may not be supported.

The third part of the code example is the source code for the two WebPart controls. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example uses dynamic compilation. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control.

No code example is currently available or this language may not be supported.

Now run the code example. Load the Web page in a browser. The first step is export a .WebPart description file for each WebPart control (for the TextDisplayWebPart and for the UserInfoWebPart control). For each control, click the verbs menu on the control (represented by the downward arrow in the title bar), and click Export. Follow the instructions to save a .WebPart description file for the control. After you have exported a description file for each control, close the Web page, and edit the page source in an editor. Delete the <aspSample:userinfowebpart> and the <aspSample:textdisplaywebpart> control declaration elements, then save and close the file. (You are doing this step to simulate a user who does not yet have these controls, so you can import the controls to the page).

Load the Web page again in a browser. Use the Display Mode drop-down list control and select Catalog to switch the page to catalog mode. In the ImportCatalogPart control, click the Browse button, browse to the .WebPart files you created, select one, then click the Upload button. A reference to the control should appear with a check box next to it. Select the check box, then click Add to add the control to the page. Repeat this process for the other control.

While you are in this view of the page, click the Get WebPart Description button near the bottom of the page to see the effect of programmatically accessing the WebPartDescription object for the control description currently loaded in the ImportCatalogPart control. The method used to access the description details, found in the Button1_Click method of the page source, is the GetAvailableWebPartDescriptions method. A label below the button displays basic details about the control.

After adding the first control, repeat the process to add the second control to the page. Finally, click Close to exit catalog mode and return the page to browse mode. Both custom controls should now appear in the page, containing the values they had when you exported description files earlier.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show: