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 服务器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)
   {
      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
End Class
 _

注解

ASP.NET 服务器控件(例如RepeaterDataListGridView 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.

适用于

另请参阅