Is there a way to prevent this from running every time a web page is loaded?

For instance I have a web page that opens up upon form load. So right when the form loads it starts running the code that is in the webbrowser document complete event.

I tried adding a counter to the event. So on the first load it incremented an integer value to 1. Then used a simple "if" statement, like "if (countInteger !=1)" then do code. Didn't work as planned though.

Hard for me to explain why, but I think it has something to do with it(web browser doc complete event) getting triggered every time something loads complete on the web page. Like if three images are on the web page it triggers the document complete event 3 times. That's my only guess, because I had to set the value to equal or greater than 10 for it work properly. Even then it wasn't consistent.

Currently my work around is using a timer instead of the web browser document complete, but I would really like to get the document complete event working the way I need. Would be faster at getting my input in.

Thanks, Gixxer.

Using Visual C# 2008.

I understand what you're saying with the document complete event being fired more than once for a navigation, but what are you trying to accomplish?

It appears the DocumentComplete event fires for each frame on the site, not for each image downloaded. If you're trying to figure out when the page load is complete in its entirety you can use this code:

private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
      SHDocVw.IWebBrowser2 doc = e.pDisp as SHDocVw.IWebBrowser2;
      if (doc != (sender as AxSHDocVw.AxWebBrowser).GetOcx())
        return;//still loading other frames
        MessageBox.Show("Done loading");

Borrowed from:

This article has been dead for over six months. Start a new discussion instead.