This documentation is archived and is not being maintained.

WebPartManager.WebPartClosing Event

Occurs during the process of removing a WebPart control (or server or user control) from a page.

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

public event WebPartCancelEventHandler WebPartClosing
/** @event */
public void add_WebPartClosing (WebPartCancelEventHandler value)

/** @event */
public void remove_WebPartClosing (WebPartCancelEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

The WebPartClosing event is raised by the OnWebPartClosing method when the WebPartManager control is in the process of closing a control. If the removal of the control is successful, this event is followed by the WebPartClosed event.

Page developers can provide a custom handler for the event by adding the OnWebPartClosed attribute to the <asp:webpartmanager> element in a page, and assigning a custom method name to the attribute.

Normally, when the WebPartClosing event is raised as a direct result of a user closing a WebPart control, the event can be cancelled. However, there is a scenario in which the event cannot be cancelled. If a WebPartZone control is deleted, the WebPart controls it contains must all be closed, otherwise they would be orphaned. In this case the WebPartManager control closes the WebPart controls, not the user. And when the WebPartManager control is in the process of calling the CloseWebPart method to close each control, and the WebPartClosing event is raised, the event cannot be cancelled (by design) because the WebPartManager needs to complete the task of cleaning up all the zone's controls.

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: