WebPartDescription Class
Assembly: System.Web (in system.web.dll)
When WebPart controls are displayed in a catalog of controls that users can add to a page, some basic information about each control is required. For example, it is useful to have a title for the control, and a description, so that as users view a catalog they have enough information to decide whether to add a control to the page. However, a catalog of WebPart controls can potentially contain many controls, and it could affect the performance of an application if an instance of every WebPart control must be created to extract the information to display in the catalog.
The WebPartDescription class exists so that it is not necessary to create an instance of a WebPart control to retrieve the information about the control that is displayed in a catalog of controls. In the Web Parts control set, a WebPartDescription object is also used in conjunction with the various CatalogPart controls when a page is in catalog display mode.
The WebPartDescription class has two overloads of its constructor, one that takes a WebPart control as a parameter when an instance is available (the WebPartDescription constructor), and one that takes several strings with information about the control as parameters (the WebPartDescription constructor).
The WebPartDescription class also has several properties designed to contain the description information for WebPart controls. The following table summarizes the WebPartDescription properties, and what property each one corresponds to in a WebPart control.
| Description property | Related part control property |
|---|---|
The following code example demonstrates programmatic use of the WebPartDescription class. Ordinarily, this type is used primarily by the Web Parts control set, but this code example is simply showing basic programmatic usage of the main description properties.
The code example has four parts:
-
A user control that enables users to change display modes on a Web page.
-
A custom WebPart control.
-
A Web page to host the other controls.
-
An explanation of how the code example works.
The first part of the code example is the user control. The source code for the user control comes from another topic. For more details about the user control, see the topic Walkthrough: Changing Display Modes on a Web Parts Page.
The second part of the code example is a custom WebPart control. 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 the approach of dynamic compilation. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Server Control.
The third part of the code example is the Web page. Near the top are two Register directives: one that registers the user control, and the other to register the custom WebPart control whose source file is located in the App_Code folder of your site. The page contains an <asp:catalogzone> element, which in turn contains declarative references to two controls: the custom WebPart control named TextDisplayWebPart, and a BulletedList Web server control that will be treated as a WebPart control at run time because the WebPartManager control will wrap it with a GenericWebPart object. Note that in the code for the Button1_Click method, the available WebPartDescription objects for the WebPart controls in the catalog are retrieved using the GetAvailableWebPartDescriptions method, and then the description details are all written out to the page.
After you load the page in a browser, use the Display Mode drop-down list control and select Catalog to change the page to catalog display mode. In the catalog, you should see the two controls that are available to be added to the page. Click the List WebPartDescription Information button, and the code writes out the values of all available WebPartDescription objects to the page. This demonstrates that you can retrieve description details for WebPart controls in a catalog without having to create instances of the controls themselves.
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.