We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

What is Bubbling Event Architecture in HTMLUI? How do i construct it?

 

The use of a common 'Event Handler' for handling the same event for all the child elements is called Bubbling Event Architecture. This helps in reducing the number of event handler declarations required by each and every child element, thereby reducing the length and complexity of the code.

The HTML elements are collected in an array by their parent name. An event handler, for a specific event, common to all the elements in the collection is defined. The bubbling event arguments for the elements are set. The element that first triggers the event is traced. Based on the element's identity, the action for the event is executed.

C#

//The elements within the BODY tag(parent element) are got in an array

IHTMLElement[] htmlelement = this.htmluiControl1.Document.GetElementsByName("body");

//A common event handler is defined for all the elements in the collection

htmlelement[0].Click += new EventHandler(body_Click);

//The bubbling event argument for the tag elements are set

BubblingEventArgs bargs = HTMLUIControl.GetBublingEventArgs(e);

//The element that first triggers the event is obtained

BaseElement elem = bargs.RootSender as BaseElement;

//The Element is verified for its identity and the event is executed

private void body_Click(object sender, EventArgs e)

{

if(elem.ID == "btn1")

{

Console.WriteLine("Button1 is clicked");

}

else if(elem.ID == "btn2")

{

Console.WriteLine("Button2 is clicked");

}

}

VB

'The elements within the BODY tag(parent element) are got in an array

Private htmlelement As IHTMLElement() = Me.htmluiControl1.Document.GetElementsByName("body")

'A common event handler is defined for all the elements in the collection

Private htmlelement(0).Click += New EventHandler(body_Click)

'The bubbling event argument for the tag elements are set

Private bargs As BubblingEventArgs = HTMLUIControl.GetBublingEventArgs(e)

'The element that first triggers the event is obtained

Private elem As BaseElement = CType(IIf(TypeOf bargs.RootSender Is BaseElement, bargs.RootSender, Nothing), BaseElement)

'The Element is verified for its identity and the event is executed

Private Sub body_Click(ByVal sender As Object, ByVal e As EventArgs)

If elem.ID = "btn1" Then

Console.WriteLine("Button1 is clicked")

Else If elem.ID = "btn2" Then

Console.WriteLine("Button2 is clicked")

End If

End Sub

The definition for the child button elements inside the parent body element in the HTML document is shown below.

C#

Article ID: Published Date: Last Revised Date: Platform: Control:
797 04/30/2011 07/10/2014 Windows Forms HTMLUIControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.