Control.RaiseBubbleEvent(Object, EventArgs) 方法


将所有事件源及其信息分配给控件的父级。Assigns any sources of the event and its information to the control's parent.

 void RaiseBubbleEvent(System::Object ^ source, EventArgs ^ args);
protected void RaiseBubbleEvent (object source, EventArgs args);
member this.RaiseBubbleEvent : obj * EventArgs -> unit
Protected Sub RaiseBubbleEvent (source As Object, args As EventArgs)



事件的源。The source of the event.


一个包含事件数据的 EventArgs 对象。An EventArgs object that contains the event data.


下面的代码示例演示如何创建一个自定义类,ChildControl,重写 Button.OnClick 方法,以调用将 Button.Click 事件发送到其父 ASP.NET 服务器控件的 RaiseBubbleEvent 方法。The following code example demonstrate how to create a custom class, ChildControl, overriding the Button.OnClick method to call the RaiseBubbleEvent method that sends the Button.Click event to its parent ASP.NET server control. 用户单击包含 ChildControl实例的 ASP.NET 页面中的按钮时,它会在包含 ChildControl 实例的父控件上引发 OnBubbleEvent 方法,并将字符串 "ChildControl 类 OnClick 方法称为" 写入页面。When the user clicks a button in an ASP.NET page that includes an instance of ChildControl, it raises the OnBubbleEvent method on the parent control that contains the instance of ChildControl and writes the string "The ChildControl class OnClick method is called" to the page.

public class ChildControl : Button
   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
   protected override void OnClick(EventArgs e) 
      Context.Response.Write("<br><br>ChildControl's OnClick called.");
      // Bubble this event to parent.
      RaiseBubbleEvent(this, e);
Public Class ChildControl
   Inherits Button
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
   Protected Overrides Sub OnClick(e As EventArgs)
      Context.Response.Write("<br><br>ChildControl's OnClick called.")
      ' Bubble this event to parent.
      RaiseBubbleEvent(Me, e)
   End Sub
End Class


RepeaterDataListGridView Web 控件等 ASP.NET 服务器控件可以包含引发事件的子控件。ASP.NET server controls such as the Repeater, DataList and GridView Web controls can contain child controls that raise events. 例如,GridView 控件中的每一行都可以包含一个或多个由模板动态创建的按钮。For example, each row in a GridView control can contain one or more buttons created dynamically by templates. 嵌套控件中的事件是 "冒泡" 的,而不是每个按钮单独引发事件,也就是说,它们被发送到控件的父级。Rather than each button raising an event individually, events from the nested controls are "bubbled" - that is, they are sent to the control's parent. 父对象进而引发名为 RowCommand 的泛型事件,其参数值为。The parent in turn raises a generic event called RowCommand with parameter values. 这些值允许您确定引发原始事件的单个控件。These values allow you to determine which individual control that raised the original event. 通过响应此单个事件,你可以避免为子控件编写单独的事件处理方法。By responding to this single event, you can avoid having to write individual event-handling methods for child controls.

尽管不能重写此方法,但作者可以通过重写 OnBubbleEvent 方法来处理或引发冒泡事件。While you cannot override this method, controls you author can handle or raise bubbled events by overriding the OnBubbleEvent method.