Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mshtml HTMLFormElement events

17 views
Skip to first unread message

Sunny

unread,
Nov 23, 2003, 5:17:16 AM11/23/03
to
Hi all,
dev. env.: VS.Net2003/C#

I have a windows form application with web browser control. I need to
capture the onsubmit event of the forms in the document in order to get
the values and log them.

I have tried this:

1.

this.current_page = this.mydoc.Document as mshtml.HTMLDocumentClass;

if (this.current_page != null)
{
mshtml.IHTMLElementCollection _forms = this.current_page.forms;

foreach (mshtml.IHTMLFormElement _form in _forms)
{
((mshtml.HTMLFormElementEvents2_Event)_form).onsubmit +=
new mshtml.HTMLFormElementEvents2_onsubmitEventHandler
(MyDoc_onsubmit);
}
}

2.
<same, just diff. foreach>
foreach (mshtml.HTMLFormElementClass _form in this.forms)
{
_form.HTMLFormElementEvents2_Event_onsubmit +=
new mshtml.HTMLFormElementEvents2_onsubmitEventHandler
(MyDoc_onsubmit);
....

And there are 2 articles on codeproject.com, they do not work also.

And ... no success. There is no exceprions, everything passes, but after
that the form submition on the page is blocked, even the submit button
does not work.

I have tried to go around this and to use BeforeNavigate2 event of the
browser (it works) and to examine if there is postdata. But in that case
I'll loose forms which has GET method.

Please, any help will be highly appreciated.

Thanks
Sunny

Jeffrey Tan[MSFT]

unread,
Nov 25, 2003, 1:36:10 AM11/25/03
to

Hi Sunny,

You can set break point in the onsubmitEventHandler to find if this method
was called.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Sunny

unread,
Nov 25, 2003, 10:37:03 AM11/25/03
to
Hi Jeffrey,

Thanks for the suggestion. I have already done this before I post. I'm
stating that it is not called, and I mean it.

Thanks
Sunny

In article <0fsWt5xs...@cpmsftngxa07.phx.gbl>, v-
je...@online.microsoft.com says...

Jeffrey Tan[MSFT]

unread,
Nov 26, 2003, 4:26:50 AM11/26/03
to

Hi Sunny,

Yes, I have tried your solution 2. I did not find any error in your code.
I will do some search into this. I will reply you ASAP.
Thanks for your understanding.

Sunny

unread,
Nov 26, 2003, 9:55:52 AM11/26/03
to
In article <vzEnr9$sDHA...@cpmsftngxa06.phx.gbl>, v-
je...@online.microsoft.com says...
Thanks
I'll wait.

Sunny

Jeffrey Tan[MSFT]

unread,
Nov 28, 2003, 1:21:42 AM11/28/03
to

Hi Sunny,

Sorry for letting you wait so long.
I still did not figure out where is the problem. I have called some
colleague to handle this issue.
We will reply you ASAP.

Ariel Molina

unread,
Dec 5, 2003, 10:49:27 AM12/5/03
to
Hello Sunny,

I tried the code below:

private void DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
doc = (mshtml.HTMLDocument)axWebBrowser1.Document;
foreach (mshtml.IHTMLFormElement cform in doc.forms)
{
mshtml.HTMLFormElementEvents_Event iEvent;
iEvent = (mshtml.HTMLFormElementEvents_Event) cform;
iEvent.onsubmit += new
mshtml.HTMLFormElementEvents_onsubmitEventHandler(OnSubmitEventHandler);

}

}

And was not able to sink the onsubmit event either. I was able to sink
other form element events however so this really is telling me that we may
be looking at a possible bug. For a workaround have you considered
sinking the onclick event of the submit button on the form? This should
accomplish the same thing.


Ariel Molina
Microsoft Online Support

Sunny

unread,
Dec 8, 2003, 11:21:02 AM12/8/03
to
Hello Ariel,
thanks for the post.
Yes, it seems that it is a bug, but can you provide me some more info
where is it - in the mshtml by itself, or in the wrapper for .Net?

I have solved the problem by capturing the BeforeNavigate2 event, and
examining Post == null of the provided event args.

But this, like sinking to the click event is half of the work.

If you hook to BeforeNavigate2, you will miss the GET method forms.
And if you sink to the onclick event, you are not sure that the form is
submitted, because it may have some validation, and not always
submitted.

I'll be glad to hear about the progress in that direction.

Thanks
Sunny

In article <n$9lcd0u...@cpmsftngxa07.phx.gbl>,
ari...@online.microsoft.com says...

Ariel Molina

unread,
Dec 15, 2003, 3:22:04 PM12/15/03
to
Hello Sunny,

The bug has been filed with the product group but at this time I cannot
give any details regarding the problem component. Just keep up to date
with the release notes for future versions of the products involved.

Thank You,

Murali K

unread,
Sep 4, 2004, 6:51:40 PM9/4/04
to
Is there any solution for the above mentioned issue? I am very
interested in the solution as I got into the same issue where the submit
button is completely disabled if a onsubmit event handler is attached to
the form.

I appreciate any help.

Murali

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

wise...@yahoo.com

unread,
Jan 5, 2005, 3:03:12 PM1/5/05
to
Hi Ariel,

I am working on a project that needs to capture the onsubmit event of a
form, and was wondering if there was any resolution to the problems
listed in this discussion. Thanks much.

Chris Mueller

0 new messages