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.

protected:
 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

參數

source
Object Object Object Object

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

args
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 伺服器控制項,方法ParentControlThe 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)
   {
      myWriter.Write("ParentControl");
      RenderChildren(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)
      myWriter.Write("ParentControl")
      RenderChildren(myWriter)
   End Sub 'Render
End Class 'ParentControl
 _

備註

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 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.

適用於

另請參閱