This documentation is archived and is not being maintained.

WebPartManager::GetGenericWebPart Method

Gets a reference to the instance of the GenericWebPart control that contains a server control.

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

public:
GenericWebPart^ GetGenericWebPart(
	Control^ control
)

Parameters

control
Type: System.Web.UI::Control

A server control that exists in a WebPartZoneBase and is wrapped as a child control of a GenericWebPart at run time.

Return Value

Type: System.Web.UI.WebControls.WebParts::GenericWebPart
A GenericWebPart that wraps control as a child control. The method returns nullptr if control is not contained in a GenericWebPart.

ExceptionCondition
ArgumentNullException

control is nullptr.

In general, there are two categories of controls that developers place in WebPartZoneBase zones to participate in Web Parts applications: WebPart controls, which inherit from the WebPart base class, and other server controls, which can be standard ASP.NET controls, custom controls, or user controls. When any of these controls is placed in a WebPartZoneBase zone, it takes on the functionality of a WebPart control. A WebPart control has this functionality inherently, but the other kinds of server controls do not. To enable the other server controls to act as WebPart controls when they are placed in a WebPartZoneBase zone, ASP.NET wraps them with a GenericWebPart control. Because the GenericWebPart control inherits directly from the WebPart class, it provides its child controls with true Web Parts features.

Often at run time, page developers might want to get a reference to the GenericWebPart control that contains one of the server controls in a zone. The GetGenericWebPart method enables them to retrieve a reference to the GenericWebPart control.

The following code example demonstrates the use of the GetGenericWebPart method. The code example contains a Calendar control declared within a WebPartZone zone. The Button1_Click method first prints the ID of the Calendar control to a label, and then uses the GetGenericWebPart method to retrieve a reference to the GenericWebPart control that wraps the calendar. The ID of the GenericWebPart control, and the ID of its child control (which is the Calendar control), are both printed to a second label.

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: