Bubble Event




I have the following:

Parent > Child > Button

Parent is a custom control. Child is another custom control added to
Button is an ASP.NET button added to Child control.

Parent has an event named Submitted. I want to fire this event when
the Button is clicked.
My first approach can be described in the following order:

1. Catch Button Click event in Child
2. Fire a ButtonWasClicked event in Child
3. Catch ButtonWasClicked event in Parent
4. Fire Submitted event in Parent

Now I got to know that there is something called BubbleEvent which
fires an event up to the control hierarchy.

I have the following, inside my Child class:

' MyButton_Click
Private Sub MyButton_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles MyButton.Click

RaiseBubbleEvent(MyButton, e)

End Sub

I am now sure if this is right and how can I catch the event in my
Parent class.

Could someone please help me out?





Basically the scheme in your class child would be something such as :
Event Submit()

Private Sub button_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button.Click

RaiseEvent Submit()

End Sub

Then when you use to child class you can react to the submit event. If used
in a parent control you can then use the same scheme to expose the submit
event to consumers.

Finally when you use the Parent class you just have to react to its submit
event wihtout ahving anyhting to know about inner controls details...



bruce barker

in the parent you override OnBubbleEvent to catch the event. From this
you raise whatever events you want. Normally to identify what type of
event was bubbled up, a custom EventArgs would be used in the

-- bruce (sqlwork.com)

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads