DeclarativeCatalogPart.GetWebPart Method

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

Returns a reference to a WebPart control based on the value of the description passed into the method.

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

public:
virtual WebPart^ GetWebPart (
	WebPartDescription^ description
) override
public WebPart GetWebPart (
	WebPartDescription description
)
public override function GetWebPart (
	description : WebPartDescription
) : WebPart

Parameters

description

A WebPartDescription that contains details about the control.

Return Value

A WebPart control whose description matches the values in description.

The GetWebPart method returns a reference to a WebPart control whose description details match the values of the WebPartDescription object passed into the method. Typically, this method is used together with the GetAvailableWebPartDescriptions method, which is used to retrieve the descriptions of all the controls in the catalog. Individual WebPart controls can then be retrieved or manipulated as needed by passing individual WebPartDescription objects to the GetWebPart method.

The following code example shows how to use the GetWebPart method. This example has four parts:

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

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

  • A Web page that contains a CatalogZone control and a DeclarativeCatalogPart control that references several server controls. The page also contains the event-handling code that calls the GetWebPart method.

  • 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. 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 source code for the two custom 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. 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.

The third part of the example is the Web page that contains the DeclarativeCatalogPart control. Notice that the Button2_Click method obtains the descriptions of the WebPart controls in the catalog, calls the GetWebPart method to retrieve a control that matches the description of the third control in the collection, and then adds that control to the page.

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

When you load the page in a browser, select Catalog Mode in the Display Mode drop-down list control to switch to catalog mode. In catalog mode, you can see the controls that are available to be added to the page. If you click the Add TextDisplayWebPart button, the control is added to the page without your having to add it through the normal catalog user interface (UI). Use the Display Mode drop-down list to return the page to normal browse mode; the control you added is visible on the page.

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: