none
WebBrowser -> DocumentCompleted event

    Question

  • Hello!

    I'm using webbrowser control in C# (Visual Studio 2008).

    The problem is that DocumentCompleted event fired on each from frame complete.

    But how to determine that the page is fully loaded?

     

    In C++ when I used webbrowser from COM object I was able to compare pDisp parameter with the browser's object.

    Please, help.

    Saturday, May 08, 2010 3:25 PM

Answers

All replies

  • Check the ReadyState property.
    • Marked as answer by Harry Zhu Friday, May 14, 2010 2:34 AM
    Saturday, May 08, 2010 4:00 PM
  • Thank you for your response, but I tried it and it is not working..

     

    Here is the code snippet I used:

               

     if (webBrowser1.ReadyState.ToString() != "Complete")
          {
            return;
          }

    It is set to Complete, but the page is not loaded yet...

    Saturday, May 08, 2010 4:04 PM
  • You have to check ReadyState in the DocumentCompleted event.

    Why are you converting an enum to a string and then performing a string comparison?

    if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
        return;

     

    • Marked as answer by Harry Zhu Friday, May 14, 2010 2:34 AM
    Saturday, May 08, 2010 7:03 PM
  • Hello, Tegiver! Thank you for you  help!

    Anyway, I'm getting this TRUE even if DocumentCompleted is called on frame load completion. So this doesn't guarantee that my code would run only once on complete page load...

    Tergiver, does this check works for you on the page with multiple frames? Any other solutions?

    Saturday, May 08, 2010 7:08 PM
  • Tergiver, does this check works for you on the page with multiple frames? Any other solutions?

    Actually, I was trusting that John and others here knew what they were talking about. If you look at this thread:
    http://social.msdn.microsoft.com/Forums/en/winforms/thread/6c1e1923-174a-4812-8a06-b04b8367e1bb

    You'll see there that I know of a guaranteed way of doing it, but not without unsafe code.

    • Marked as answer by Harry Zhu Friday, May 14, 2010 2:34 AM
    Saturday, May 08, 2010 8:26 PM
  • I have read on several threads the Readystate solution, this is not correct. On a page with multiple frames documentcompleted is fired multiple times, on each occasion readystate = complete.

    I don't understand why people are quoting this as a correct answer?

    webbrowser1.ReadyState = ReadyState.Completed  every time the documentcompleted event fires (multiple times for a single page with multiple frames).

    Is there ANY definitive method in vb.net to determine when the documentcompleted event won't be fired?

    Sunday, January 06, 2013 2:17 PM
  • Comparing the URL's and detecting ReadyState.Complete is usually sufficient.  If you have problems, add this statement to the DocumentCompleted event

        Console.WriteLine(e.Url.ToString + " " + WebBrowser1.ReadyState.ToString)

    to observe the behavior of a particular site.

    Sunday, January 06, 2013 3:32 PM
  • Thanks John, will give this a try. Eventually coded around my 'problem'.
    Friday, January 11, 2013 8:39 AM