Export (0) Print
Expand All

Control.OnBubbleEvent Method

Determines whether the event for the server control is passed up the page's UI server control hierarchy.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

protected virtual bool OnBubbleEvent(
	Object source,
	EventArgs args
)

Parameters

source
Type: System.Object

The source of the event.

args
Type: System.EventArgs

An EventArgs object that contains the event data.

Return Value

Type: System.Boolean
true if the event has been canceled; otherwise, false. The default is false.

ASP.NET server controls such as the Repeater, DataList and GridView Web controls can contain child controls that raise events. 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. 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.

The following example overrides the OnBubbleEvent method in a custom ASP.NET server control, ParentControl. This method is invoked when a child control of ParentControl calls the RaiseBubbleEvent method. 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);
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft