|
-
Dec 4th, 2009, 08:34 AM
#1
Thread Starter
Addicted Member
Webbrowser click fires twice
In VS2005 I am using click on some elements in a webbrowser document to perform certain functions, eg print or open MS Paint but for some reason all the mouse events fire twice. A second click on the same element might be intentional so I can't just bypass code if the ID is the same as last time. There are no other calls of Document_Click anywhere in the project.
Main code is:-
Private Sub mainbox2_DocCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
MainBox2.Document.AddHandler .Click, New HtmlElementEventHandle (AddressOf Document_Click)
End Sub
Private Sub Document_Click(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
etc - code here gets done twice
I supposes I could stick a timer on it and ignore any within 1s say but cheers for any more elegant solutions.
Last edited by xoggoth; Dec 4th, 2009 at 08:51 AM.
-
Dec 4th, 2009, 08:48 AM
#2
Re: Webbrowser click fires twice
First of all, where is the handles clause on the DocCompleted event? Are you manually wiring up the DocCompleted routine to the browsers documentcompleted event?
Either way, my guess is that DocCompleted is firing twice, so the handler for Document_Click is being added twice, which results in your code being run twice.
Set a break point on your DocCompleted routine, and see how many times it is hit when your code runs.
-
Dec 4th, 2009, 09:47 AM
#3
Thread Starter
Addicted Member
Re: Webbrowser click fires twice
Add of WebBrowserDocumentCompletedEventHandler is done in code but it definitely only passes through there once.
However, you have put me on right track, as it is the mainbox2_DocCompleted being done more than once and adding extra handlers. On first run it was going through twice due to init on setup with a blank document. (A legacy from a frig needed in an old VB6 version).
However, there is a further oddity, debug shows that immediately after click sub finishes it enters the doccompleted sub. I suspect that perhaps WebBrowserDocumentCompleted is fired on any browser event complete and is not actually the right function to use, I need a page load completed event.
Thanks very much for your help.
-
Dec 4th, 2009, 09:50 AM
#4
Re: Webbrowser click fires twice
DocumentCompleted only fires when the page has been loaded to the browser.
The only cases I have seen where a documentcompleted event fires more than 1 time for a single navigation is
1) the page is a frames page, which will fire documentcompleted once for each frame, and one final time for the parent frames page
2) the webpage itself has code to perform a navigation on certain action, causing the page to reload or navigate somewhere else, causing the documentcompleted event to fire again.
-
Dec 4th, 2009, 10:08 AM
#5
Thread Starter
Addicted Member
Re: Webbrowser click fires twice
Not sure what's going on in that case as there are no frames or jscript, they are virtually blank test pages at moment. However, the finished pages will have complex jscript that may well do that so I need to cater for it. Checking if doc title changed and keeping track of number of handlers should sort it. (I hope)
Thanks again.
Update:Just a deletehandler before each addhandler works, no obvious probs.
PS Document.body has some wierd junk in it that has nothing to do with my project. The cookie specified is some old webpage I haven't visited for months and then only in normal IE.
Last edited by xoggoth; Dec 4th, 2009 at 12:15 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|