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


決定伺服器控制項的事件是否要在頁面的 UI 伺服器控制項階層架構中向上傳遞。Determines whether the event for the server control is passed up the page's UI server control hierarchy.

 virtual bool OnBubbleEvent(System::Object ^ source, EventArgs ^ args);
protected virtual bool OnBubbleEvent (object source, EventArgs args);
abstract member OnBubbleEvent : obj * EventArgs -> bool
override this.OnBubbleEvent : obj * EventArgs -> bool
Protected Overridable Function OnBubbleEvent (source As Object, args As EventArgs) As Boolean


Object Object Object Object

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

EventArgs EventArgs EventArgs EventArgs

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


如果事件已取消,則為 true,否則為 falsetrue if the event has been canceled; otherwise, false. 預設為 falseThe default is false.


下列範例會覆寫OnBubbleEvent自訂 ASP.NET 伺服器ParentControl控制項中的方法。The following example overrides the OnBubbleEvent method in a custom ASP.NET server control, ParentControl. 當的ParentControl子控制項RaiseBubbleEvent呼叫方法時,就會叫用這個方法。This method is invoked when a child control of ParentControl calls the RaiseBubbleEvent method. 發生這種情況時ParentControl ,類別會將兩個字串寫入包含的 ASP.NET 網頁,第一個OnBubbleEvent表示已呼叫其方法,第二個則識別RaiseBubbleEvent方法的原始檔控制。When this happens, the ParentControl class writes two strings to the containing ASP.NET page, the first stating that its OnBubbleEvent method has been called, the second identifying the source control of the RaiseBubbleEvent method.

public class ParentControl : Control 
   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
   protected override bool OnBubbleEvent(object sender, EventArgs e)
      Context.Response.Write("<br><br>ParentControl's OnBubbleEvent called.");
      Context.Response.Write("<br>Source of event is: " + sender.ToString());
      return true;
   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
   protected override void Render( HtmlTextWriter myWriter)
Public Class ParentControl
   Inherits Control
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
   Protected Overrides Function OnBubbleEvent(sender As Object, e As EventArgs) As Boolean
      Context.Response.Write("<br><br>ParentControl's OnBubbleEvent called.")
      Context.Response.Write(("<br>Source of event is: " + sender.ToString()))
      Return True
   End Function 'OnBubbleEvent
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
   Protected Overrides Sub Render(myWriter As HtmlTextWriter)
   End Sub
End Class


ASP.NET 伺服器控制項(例如Repeater、和DataList GridView Web 控制項)可以包含引發事件的子控制項。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 naming container. 命名容器接著會引發名RowCommand為且具有參數值的一般事件。The naming container 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.