0

Every code example for submitting a form inside a WebBrowser control I have seen so far, hardcodes the WebBrowser.Document.Forms[0].InvokeMember() parameter as "submit".

Must this parameter always be "submit"?

If so, then why is it a parameter?

If not, what are the rules for specifying which string to put there? Is it dependent on the HTML of the page being accessed?

Update 1: The documentation for InvokeMember() clearly shows an example of using a value other than "submit". So, at least I got the answer: No.

But I still don't understand when should I use "submit" and when should I use "moveRow": In the web page I am handling via "submit" there is no mention of that string, yet it works perfectly. Where is that implied "submit" hiding in the web page?

Update 2: Ah! I think I am beginning to get it: It's a Javascript built-in method. And thus implied for any DOM Form element.

An authoritative answer is most appreciated.

Community
  • 1
  • 1
ih8ie8
  • 944
  • 8
  • 23

2 Answers2

1

No, it doesn't have to be "submit". But that's certainly the most popular method you'd ever use with a form. The Winforms HtmlDocument and HtmlElement classes are wrappers for the DOM interfaces. Core ones in this case are IHtmlDocument2 (matching HtmlDocument) and IHtmlElement2 (matching HtmlElement). With a raft of specific interface types, like IHtmlFormElement to represent a form object in the DOM. But without a matching class for those in Winforms, HtmlElement wraps them all. Which is why you need to use InvokeMember(), same idea as reflection's Type.InvokeMember(). It makes up for methods that are not wrapped by HtmlElement. Like IHtmlFormElement::submit().

The one advantage of HtmlElement is that it helps you avoid the morass of versions of these DOM interfaces. There are seven versions of IHtmlDocument for example. Every time Microsoft improves IE, they tend to have to create another version of the interface with the additional members added.

You certainly can use them early bound. Add a reference to c:\windows\system32\mshtml.tlb. Cast the WebBrowser.ActiveXInstance to mshtml.IHtmlDocument to use it.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

InvokeMember calls the form element's methods/properties via IDispatch::Invoke. You can find the list of methods and properties that you can invoke from IE's documentation of the form element.

Easier binding via IE's type library ensures type safety but you need to find the correct interface for the method/property, which means for the form element, you need to look under IHTMLElementX if the method/property cannot be found under IHTMLFormElementX.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46