WebPartManager.WebPartsDisconnecting 事件

定义

在结束以前连接的 WebPart 或服务器控件之间的连接的过程中发生。Occurs during the process of ending the connection between previously connected WebPart or server controls.

public:
 event System::Web::UI::WebControls::WebParts::WebPartConnectionsCancelEventHandler ^ WebPartsDisconnecting;
public event System.Web.UI.WebControls.WebParts.WebPartConnectionsCancelEventHandler WebPartsDisconnecting;
member this.WebPartsDisconnecting : System.Web.UI.WebControls.WebParts.WebPartConnectionsCancelEventHandler 
Public Custom Event WebPartsDisconnecting As WebPartConnectionsCancelEventHandler 

注解

此事件由方法引发,它指示用户单击了DisconnectWebParts断开连接谓词,或已调用方法。 OnWebPartsDisconnecting WebPartsDisconnectingThe WebPartsDisconnecting event is raised by the OnWebPartsDisconnecting method, and it signals the fact that a user has clicked a disconnect verb, or the DisconnectWebParts method has otherwise been called. 事件提供了一种方法,可在连接完成前取消结束连接的过程。The event provides an opportunity to cancel the process of ending a connection before it is complete. 如果连接成功结束,则此事件后跟WebPartsDisconnected事件。If the connection is ended successfully, this event is followed by the WebPartsDisconnected event.

页面开发人员可以为事件添加自定义处理程序,方法OnWebPartsDisconnecting是将属性<asp:webpartmanager>添加到元素,并将自定义方法名称分配给该属性。Page developers can add a custom handler for the event by adding the OnWebPartsDisconnecting attribute to the <asp:webpartmanager> element, and assigning a custom method name to the attribute.

通常,当WebPartsDisconnecting事件由于结束连接的用户操作的直接结果引发时,可以取消该事件。Normally, when the WebPartsDisconnecting event is raised as a direct result of a user's action that ends a connection, the event can be cancelled. 但是,在某些情况下,无法取消事件。However, there are several scenarios in which the event cannot be cancelled. 第一种情况是,如果WebPartZone删除控件,则该WebPart控件所包含的控件必须全部关闭,否则将会孤立。The first scenario is, if a WebPartZone control is deleted, the WebPart controls it contains must all be closed, otherwise they would be orphaned. 在这种情况WebPartManager下,控件WebPart将关闭控件,而不是用户,并且它还必须能够在不中断的情况下终止任何连接的控件的连接,使其能够完成清理和关闭过程所有控件。In this case the WebPartManager control closes the WebPart controls, not the user, and it must also be able to terminate the connections of any connected controls without any chance of interruption, so that it can complete the process of cleaning up and closing all the controls. 因此,在这种WebPartsDisconnecting情况下,不能取消设计方法。Therefore, by design the WebPartsDisconnecting method cannot be cancelled in this scenario. 有关可取消的相关事件,请参阅WebPartClosing事件。For a related event that can be cancelled, see the WebPartClosing event.

不能取消WebPartsDisconnecting事件的第二种情况是ActivateConnections调用方法(例如,在每次向页面发出请求时调用此方法),而页面上的现有连接中存在某种类型的冲突。The second scenario in which the WebPartsDisconnecting event cannot be cancelled is when the ActivateConnections method is called (this called during each request to a page, for example), and there is some type of conflict in the existing connections on a page. 例如,用户可能会将 control x 连接到 control y,但共享用户将 control x 连接到 control z,但不允许 control x 建立多个连接。For example, perhaps a user connects control x to control y, but a shared user connects control x to control z, and yet control x is not allowed to form multiple connections. 在这种情况下,将优先使用单个用户的连接设置,并且该WebPartManager控件通过DisconnectWebPart调用方法并结束 x 和 z 与特定用户之间的连接来解决冲突。In this case, the individual user's settings for the connection take precedence, and the WebPartManager control resolves the conflict by calling the DisconnectWebPart method and ending the connection between x and z for the particular user. 由于此断开连接对于解决冲突至关重要,因此设计WebPartsDisconnecting该事件在此方案中不能取消。Because this disconnection is essential to resolving the conflict, by design the WebPartsDisconnecting event cannot be cancelled in this scenario.

不能取消WebPartsDisconnecting方法的第三种情况是WebPart :当前连接的或服务器控件被删除或关闭。The third scenario in which the WebPartsDisconnecting method cannot be cancelled is when a WebPart or server control that is currently connected is either deleted or closed. 由于控件确实要从页中移除,因此,删除其连接是一种合乎逻辑的必要性。Because the control is definitely going to be removed from the page, it is a logical necessity to remove its connection. 因此,当WebPartManager控件DisconnectWebPart调用方法, WebPartsDisconnecting而该方法反过来引发事件时,设计将无法取消事件。Therefore, when the WebPartManager control invokes the DisconnectWebPart method, which in turn raises the WebPartsDisconnecting event, by design there is no possibility of canceling the event.

适用于

另请参阅