testing to see if an event has fired

  • Thread starter Thread starter Andy B
  • Start date Start date
A

Andy B

I have some code that needs to go in a WebBrowser.DocumentComplete event.
The problem is that the code doesn't run for some reason. Here is the code:

BugFixList.Items.Add("Test")
it seems like any code that isn't directly related to the
WebBrowser.Document gets ignored and isn't ran. The alternative is to put
the extra code inside of a button_click event, but the problem is that the
code needs to be ran after the WebBrowser.DocumentComplete event has
finished its work. How do I do something like this and be clean, simple and
practicle with my code?
 
I have some code that needs to go in a WebBrowser.DocumentComplete event.
The problem is that the code doesn't run for some reason. Here is the code:

BugFixList.Items.Add("Test")
it seems like any code that isn't directly related to the
WebBrowser.Document gets ignored and isn't ran. The alternative is to put
the extra code inside of a button_click event, but the problem is that the
code needs to be ran after the WebBrowser.DocumentComplete event has
finished its work. How do I do something like this and be clean, simple and
practicle with my code?

Normally, you must use Webbrowser's DocumentCompleted Event like:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
BugFixList.Items.Add("Test")
End Sub

However, as you describe, you want to use the code using a button by
calling click event eventhough you don't click, then you can use
PerformClick method in Webbrowser's DocumentCompleted event sub to
simulate it:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
Button1.PerformClick()
End Sub

....and button 1 holds your main code:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'your main code
BugFixList.Items.Add("Test")
End Sub

However, keep in mind that, your button's click event will be invoked
only when DocumentCompleted event is fired, so there's no best option
besides relying on DocumentCompleted event based on your description.

Hope this helps,

Onur Güzel
 
Is there any reason why Listbox.Items.Add("test") doesn't work inside of
webbrowser.documentcomplet event? it is really strange this stuff is going
on like that.
I have some code that needs to go in a WebBrowser.DocumentComplete event.
The problem is that the code doesn't run for some reason. Here is the
code:

BugFixList.Items.Add("Test")
it seems like any code that isn't directly related to the
WebBrowser.Document gets ignored and isn't ran. The alternative is to put
the extra code inside of a button_click event, but the problem is that the
code needs to be ran after the WebBrowser.DocumentComplete event has
finished its work. How do I do something like this and be clean, simple
and
practicle with my code?

Normally, you must use Webbrowser's DocumentCompleted Event like:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
BugFixList.Items.Add("Test")
End Sub

However, as you describe, you want to use the code using a button by
calling click event eventhough you don't click, then you can use
PerformClick method in Webbrowser's DocumentCompleted event sub to
simulate it:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
Button1.PerformClick()
End Sub

....and button 1 holds your main code:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'your main code
BugFixList.Items.Add("Test")
End Sub

However, keep in mind that, your button's click event will be invoked
only when DocumentCompleted event is fired, so there's no best option
besides relying on DocumentCompleted event based on your description.

Hope this helps,

Onur Güzel
 
Is there any reason why Listbox.Items.Add("test") doesn't work inside of
webbrowser.documentcomplet event? it is really strange this stuff is going




Normally, you must use Webbrowser's DocumentCompleted Event like:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
BugFixList.Items.Add("Test")
End Sub

However, as you describe, you want to use the code using a button by
calling click event eventhough you don't click, then you can use
PerformClick method in Webbrowser's DocumentCompleted event sub to
simulate it:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As
System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
_
Handles WebBrowser1.DocumentCompleted
Button1.PerformClick()
End Sub

...and button 1 holds your main code:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'your main code
BugFixList.Items.Add("Test")
End Sub

However, keep in mind that, your button's click event will be invoked
only when DocumentCompleted event is fired, so there's no best option
besides relying on DocumentCompleted event based on your description.

Hope this helps,

Onur Güzel

I tried to navigate "http://www.google.com" with webbrowser control,
and in webbrowser's "DocumentCompleted" event, i wrote;

Listbox1.Items.Add("Test")

....and the item was added to the listbox1.

Maybe your problem is site-specific or related to other thing such as
conditionals in the rest of your code.

Hope this helps,

Onur Güzel
 
Back
Top