Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Method


指派事件的任何來源和它的資訊至控制項的父控制項。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)


Object Object Object Object

事件的來源。The source of the event.

EventArgs EventArgs EventArgs EventArgs

包含事件資料的 EventArgs 物件。An EventArgs object that contains the event data.


下列程式碼範例示範如何建立自訂類別,ChildControl覆寫,Button.OnClick方法來呼叫RaiseBubbleEvent方法,以將傳送Button.Click與其父系 ASP.NET 伺服器控制項的事件。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. 當使用者按一下按鈕,以在 ASP.NET 網頁,其中包含的執行個體ChildControl,便會產生OnBubbleEvent包含執行個體的父控制項上的方法ChildControl,並將字串寫入 「 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 'OnClick
End Class 'ChildControl 


ASP.NET 伺服器控制項,例如RepeaterDataListGridViewWeb 控制項可以包含引發事件的子控制項。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.