This documentation is archived and is not being maintained.

WebPartManager::GetCurrentWebPartManager Method

Retrieves a reference to the current instance of the WebPartManager control on a page.

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

public:
static WebPartManager^ GetCurrentWebPartManager(
	Page^ page
)

Parameters

page
Type: System.Web.UI::Page
The Web page that contains an instance of the WebPartManager.

Return Value

Type: System.Web.UI.WebControls.WebParts::WebPartManager
A WebPartManager that references the current instance of the control on a page.

ExceptionCondition
ArgumentNullException

page is nullptr.

The GetCurrentWebPartManager method is useful in contexts where you want to retrieve a reference to the current WebPartManager control. A common scenario where this would occur is if you are writing a custom control that cannot know during development what the ID of the WebPartManager control on its page will be.

NoteNote

The GetCurrentWebPartManager method is static, so you can call it directly without needing an instance of a WebPartManager control.

Some controls in the Web Parts control set, such as WebPart controls, have a WebPartManager property that can retrieve a reference to the current WebPartManager control. Hence, when working with such controls, you should use this property to retrieve a reference.

If you are coding in a context where you know the ID of the WebPartManager control, such as writing code inline within a Web page, it is simplest and most efficient to refer directly to the WebPartManager control by using its ID.

The following code example demonstrates how to use the GetCurrentWebPartManager method. The example has two parts: a custom server control, and a Web page that hosts the control.

The custom Label control uses the GetCurrentWebPartManager method to retrieve the ID of the WebPartManager control on the current page, and then displays the ID.

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

The following code example provides the Web page that hosts the control in a WebPartZone zone.

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

After you load the page in a browser, notice that the ID of the current WebPartManager control is displayed within the custom Label control.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: