Groups | Blog | Home
all groups > vb.net controls > april 2007 >

vb.net controls : How do I handle HTML button onclick event through AxWebBrowser control...


hzgt9b
4/16/2007 10:06:37 AM
Using VS2003, VB.NET,
I have a windows app the has a AxSHDocVw.AxWebBrowser control. One of
the pages that gets loaded in the AxSHDocVw.AxWebBrowser control has a
button that the user clicks to submit information... I need my VB.NET
winsdows application to reeact to this HTML onclick event. I'm really
not sure how to accomplish this... any pointers would be greatly
appreciated.

celoftis
kal
4/16/2007 2:00:28 PM
[quoted text, click to view]

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1435668&SiteID=1


Attach onclick event to link element.

private void webBrowserSecured_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)

{

HtmlElement btn = WebBrowser1.Document.GetElementById("Button1") as
HtmlElement;

btn.AttachEventHandler("onclick", new EventHandler(ButtonClicked));

}



private void ButtonClicked(object sender, EventArgs e)

{



string txt1 = ((mshtml.HTMLInputElementClass)
(WebBrowser1.Document.GetElementById("TextBox1").DomElement)).IHTMLInputElement_value;

}



WebBrowser1.Document.GetElementById("ElementId").DomElement gives the
element type.

hzgt9b
4/16/2007 2:22:05 PM
Thanks for the quick reply.

I'll give that a try...


To muddy the water a bit, I'm not looking for submitted string but
rather I'll be trying to determine which radio button in a radio
button group has been selected... I assume I'll just be able to get to
this from the DOM elements exsposed by the AxWebBrowser's document
object - is that correct?

kal
4/16/2007 3:11:15 PM
[quoted text, click to view]

I believe as long as you know the ElementID/name of the radio button
you should be able to get it.
hzgt9b
4/16/2007 7:48:46 PM
Great - thanks again fro the help...
Once I test it out I'll reply here with my results....
hzgt9b
4/17/2007 1:14:32 PM
A couple of other issue I know that I will run into:
(1) the pages (HTM) I am loading produce multiple
"...DocumentCompleted" events - I believe this is because the pages do
javascript redirects based on object detection. Regardless, do you
know of a way to reliably determine if the browser is still loading
content (some of the pages that may also have iframes/frames).

(2) not all the documents that will be opened in the AxWebBrowser
control will be HTM... some will be PDFs or some other MS office
document. Therefore, I won't be able to blindly attached "onclick"
events when the "...DocumentCompleted" event fires. So, is there a way
to determine what type object has just "completed".... and of course
what type of object will I be looking for when my HTM pages load.
hzgt9b
5/15/2007 6:33:21 AM
I've just started trying to implement this... but I'm running into
problems.
Right off the bat, when I try to use intillisense to get my "Browser"
properties, the only property avaliable under "Document" is
"GetType"... "GetElementById..." isn't listed. Also, I am not able
reference the "HTMLElement" object...

I figure this must be a reference/import issue - so here's what I have
now:
Imports System
Imports System.IO
Imports mshtml 'Just added...

Under references, I do have a reference to MSHTML...

What else am I missing?
AddThis Social Bookmark Button