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
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.
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...
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
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.
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
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...
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,
I appreciate any help.
Murali
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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