Export (0) Print
Expand All
Expand Minimize

WebPartManager.CopyWebPart Method

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

Used by the Web Parts control set to create a copy of a WebPart or server control for the purpose of adding the control to a Web page.

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

protected virtual WebPart CopyWebPart (
	WebPart webPart
)
protected WebPart CopyWebPart (
	WebPart webPart
)
protected function CopyWebPart (
	webPart : WebPart
) : WebPart

Parameters

webPart

The WebPart or server control to be copied.

Return Value

A WebPart to be added to a page.

You cannot call the CopyWebPart method directly from your code. This method is called internally by the WebPartManager control as part of the process of adding a new dynamic WebPart or server control to a page. A dynamic control is added to a page programmatically or through the Web Parts user interface (UI), for example by a user adding a control from a catalog of controls, as opposed to a static control, which is declared directly in the markup of a page.

NoteNote

The method can be overridden in a derived class if developers want to enable the method to handle additional control copying scenarios. For details, see the Notes to Inheritors section.

When a new dynamic control is added, if it is a WebPart control, the CopyWebPart method returns a new instance of the control. If the control being added is some other type of server control (such as a user control, a custom control, or an ASP.NET control), the control will already have been wrapped with a GenericWebPart object by the Web Parts control set. When the CopyWebPart method encounters a GenericWebPart control, it returns a new instance of the GenericWebPart control with a new instance of the child control wrapped within it.

When the CopyWebPart method creates a new copy of a control to return, it also resets the values of all the properties to their default values. Note that, if you want to preserve the values of the personalizable properties and have them copied to the new control instance, you should call the CopyPersonalizationState method as well. The final step carried out by the CopyWebPart method is to call the CreateDynamicWebPartID method to obtain a new ID for the control.

NoteNote

Because the method obtains a new ID for a copied control, you should not rely on referencing a dynamic control that is added to a page by its original ID. Instead, you should reference the new instance of the control returned by the method.

Notes to Inheritors The method is declared as virtual so that developers could inherit from the WebPartManager class, override the method, and provide for additional scenarios in which it could create copies of controls. For example, the method could optionally receive as input a control that has been serialized into an XML file. The method could deserialize the XML (if present), and then call the base method to handle the existing cases and to return a new instance of a WebPart control.

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:
© 2014 Microsoft