Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Control.OnBubbleEvent Method

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

[Visual Basic]
Protected Overridable Function OnBubbleEvent( _
   ByVal source As Object, _
   ByVal args As EventArgs _
) As Boolean
[C#]
protected virtual bool OnBubbleEvent(
 object source,
 EventArgs args
);
[C++]
protected: virtual bool OnBubbleEvent(
 Object* source,
 EventArgs* args
);
[JScript]
protected function OnBubbleEvent(
   source : Object,
 args : EventArgs
) : Boolean;

Parameters

source
The source of the event.
args
An EventArgs object that contains the event data.

Return Value

true if the event has been canceled; otherwise, false. The default is false.

Remarks

ASP.NET server controls such as the Repeater, DataList and DataGrid Web controls can contain child controls that raise events. For example, each row in a DataGrid 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 ItemCommand 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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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
 _

[C#] 
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);
   }
}

[C++] 
public __gc class ParentControl : public Control
{
protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
   bool OnBubbleEvent(Object* sender, EventArgs* e)
   {
      Context->Response->Write(S"<br><br>ParentControl's OnBubbleEvent called.");
      Context->Response->Write(String::Concat(S"<br>Source of event is: {0}", 
         sender->ToString()));
      return true;
   }

protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
   void Render(HtmlTextWriter* myWriter)
   {
      myWriter->Write(S"ParentControl");
      RenderChildren(myWriter);
   }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | RaiseBubbleEvent | Bubbling an Event

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.