mshtml HTMLFormElement events

  • Thread starter Thread starter Sunny
  • Start date Start date
S

Sunny

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
 
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.
 
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
 
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.

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.
 
v- said:
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.

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.
Thanks
I'll wait.

Sunny
 
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.

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.
 
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
 
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
 
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,
Ariel Molina
Microsoft Online Support
 
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
 
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
 
Back
Top