0

So, short question was that.

Longer version: The problem i'm facing is that i rely on pairs of webbrowser.navigate and navigated event in my app, but for each navigate method, the navigated event is triggered multiple times. It seems like the url is loaded in parts and each one triggers the event again or something alike. May the use of Document.links or HtmlElement or something trigger the navigate again?

Code is like:

    private void btGo_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate(cboWeb.Text);
    }

  private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        foreach (HtmlElement link in webBrowser2.Document.Links)
             doStuff();
    }
}
Cristo
  • 700
  • 1
  • 8
  • 20
  • 1
    Maybe this can be helpful : http://stackoverflow.com/questions/11763189/webbrowser-document-completed-event-c-sharp AND http://stackoverflow.com/questions/2328835/why-is-webbrowser-documentcompleted-firing-twice – Mate Jan 01 '13 at 22:09
  • 1
    Have you tried DocumentCompleted? Is it also triggered multiple times? – aliassce Jan 01 '13 at 22:19
  • I fear I have chosen wrong method then... I'll change it and come back – Cristo Jan 01 '13 at 22:34
  • No, it's loading multiple times the documentcompleted event too. – Cristo Jan 01 '13 at 22:40

1 Answers1

0

Why is WebBrowser_DocumentCompleted() firing twice?

Seems like javascript or ajax or other scripts (and frames) make it reload. Thanks to the responses.

Community
  • 1
  • 1
Cristo
  • 700
  • 1
  • 8
  • 20