.NET form and Web Browser control

G

Guest

I have a .NET VB form that contains a Web Browser control. In the document in
the Web Browser I have JavaScript that responds to certain click events
within nodes (not buttons or other controls). How do I get information about
the click event back to the parent VB form? I want the parent form to update
certain information based on the ID of the node.
 
G

Guest

1. Include a reference to MSHTML
2. Obtain a reference to the document object. You will notice that the
MSHTML library contains and HTMLDocument Class that you can use as a
reference type.

E.G.
Dim doc as HTMLDocument = AxWebBrowser1.document

I would do this on an AfterNavigate2 event.

3. Using the document class you'll be able to get a reference to the
specific element that raises the event. (use the getElementById method)

4. After you have a reference to the element, you will be able to set up
event handlers for events raised by that specific html element. Just remeber
to declare the reference withevents.

e.g. (to handle node clicks from a telerik treeview i did the following)

Protected WithEvents HtmlDiv_TvwApplications As mshtml.HTMLDivElementClass
.....

HtmlDiv_TvwApplications = HtmlDoc_Document.getElementById("elementname")

'this is how i declared the event handlers

Private Function TreeContextDblClick(ByVal e As mshtml.IHTMLEventObj) As
Boolean Handles HtmlDiv_TvwApplications.HTMLElementEvents2_Event_ondblclick

'You can get more info on the element that generated the event from "e"
Dim att As String = e.srcElement.parentElement.getAttribute("rtvalue")
'code in here
end function

Hope that points you in the right direction

Sasa Milovic
..Net Developer
 

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

Top