PageCatalogPart::GetWebPart Method
Returns a reference to a WebPart control based on the value of the description passed into the method.
Assembly: System.Web (in System.Web.dll)
Parameters
- description
- Type: System.Web.UI.WebControls.WebParts::WebPartDescription
A WebPartDescription that contains details about the control.
Return Value
Type: System.Web.UI.WebControls.WebParts::WebPartA reference to the actual instance of a closed WebPart control whose description matches description.
| Exception | Condition |
|---|---|
| ArgumentNullException | description is nullptr. |
| ArgumentException | description is not an available WebPartDescription value. |
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 GetWebPart 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 PageCatalogPart 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.
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 Web Server Control.
The third part of the example is the Web page that contains the PageCatalogPart control. Notice that the Button2_Click method obtains the descriptions of the WebPart controls in the catalog, calls the GetWebPart method to retrieve all the controls in the page catalog for a collection, and then adds those controls back to the page.
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. Add one or more controls to the page, and then use the Display Mode drop-down list control to return the page to browse mode. Click the verbs menu (the downward arrow) in the title bar of one or more of the controls, and click Close. Return the page to catalog mode, and notice that now the control or controls you closed appear in the page catalog, and are available to be added back to the page. Click the Add WebPart Controls button to add the controls in the page catalog back to the page. Use the Display Mode drop-down list control to return the page to normal browse mode; the controls you added are visible on the page.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.