WebPartManager.CopyWebPart Method
Assembly: System.Web (in system.web.dll)
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.
Note |
|---|
| 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.
Note |
|---|
| 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. |
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.
Note