This documentation is archived and is not being maintained.

WebPartManager::CreateWebPart Method

Wraps a server control that is not a WebPart control with a GenericWebPart object, so that the control can have Web Parts functionality.

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

public:
virtual GenericWebPart^ CreateWebPart(
	Control^ control
)

Parameters

control
Type: System.Web.UI::Control

A server control that is not a WebPart control.

Return Value

Type: System.Web.UI.WebControls.WebParts::GenericWebPart
A GenericWebPart that wraps control and enables it to function as a true WebPart control.

The CreateWebPart method is the main mechanism for enabling server controls that are not WebPart controls to take on the same functionality as a WebPart control, and thus to participate fully in Web Parts applications. By using this method, developers vastly expand the number of server controls that they can use in a Web Parts application, because virtually any type of server control--standard ASP.NET controls, user controls, and custom controls--can be used.

The WebPartManager control also uses this method in two other scenarios to wrap server controls with a GenericWebPart object. When users add server controls to a page by using the ImportCatalogPart control, if the imported control is not a WebPart control, the CreateWebPart method is called. Also, when server controls are declared in persistence format within a WebPartZoneBase zone on a Web page, the CreateWebPart method is called for any controls that are not WebPart controls.

When you add a server control to a zone programmatically, a typical approach is to use the CreateWebPart method to wrap the control with a GenericWebPart object, and then call the AddWebPart method to add the control to the collection of all WebPart controls on the page, which is referenced by the WebParts property.

Notes to Inheritors:

This method can be overridden to use a derived GenericWebPart class instead of the base class provided with the Web Parts control set.

The following code example demonstrates use of the CreateWebPart method. In the Button2_Click method, the CreateWebPart method is called to wrap a Calendar control with a GenericWebPart object before adding it to the zone.

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

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: