Windows Develop Bookmark and Share   
 index > Windows Forms General > WebBrowser ReadyState not working.
 

WebBrowser ReadyState not working.

while (webBrowser1.ReadyState != WebBrowserReadyState.Complete || webBrowser1.IsBusy)

{

Application.DoEvents();

}

At somepages this pease og code returns even if the page has not finished loading. My guess it has something todo withpages waiting for javascripts. Is there a way to ensure that there is no more navigating?

On forehand thx.

Thomas Segato

Segato  Thursday, July 27, 2006 7:22 AM

DocumentCompleted should only be raised once when it really is completed.Navigating event will be fired for every frame though. Do you have an example ofa site that gives multiple DocumentCompleted events?

WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler
(DocumentCompletedHandler);
wb.Navigate("http://forums.microsoft.com/msdn");

private void DocumentCompletedHandler(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Done!
}

Andreas Johansson  Monday, July 31, 2006 9:00 PM
The proper way would be to handle the DocumentCompleted event instead of looping for the proper state.
Andreas Johansson  Sunday, July 30, 2006 2:26 AM

Hi Thx for your reply. Can you show a code snippet? When do you know its the last Document_Completed? Most sites raises 5-10 document completed.

On forehand thx.

Thomas

Segato  Sunday, July 30, 2006 8:02 AM

DocumentCompleted should only be raised once when it really is completed.Navigating event will be fired for every frame though. Do you have an example ofa site that gives multiple DocumentCompleted events?

WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler
(DocumentCompletedHandler);
wb.Navigate("http://forums.microsoft.com/msdn");

private void DocumentCompletedHandler(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Done!
}

Andreas Johansson  Monday, July 31, 2006 9:00 PM

Hi and thx for your reply,

DocumentCompleted will be fired after every redirection. Check http://www.flybillet.dk. So this solution is not that good. But thanks anyway.

Best regards

Thomas

Segato  Tuesday, August 01, 2006 6:17 AM

Hi there.

How would you explain the fact that when DocumentComplete is raised, even if I have a full Microsoft news email page loaded into my WebBrowser, webbrowser1.DocumentText is only "<HTML></HTML>" ??

(I load the HTML contents from a localMHT file)

smoothcoder  Wednesday, August 23, 2006 9:36 AM
This was driving me crazy.

I was trying to post data like this:
Code Snippet

WebBrowser browser = new WebBrowser();
browser.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(handler);
browser.Navigate("<url>","<windowname>",<data>,"Content-Type: application/x-www-form-urlencoded");

and the DocumentComplete event would never fire.


so then I tried:
Code Snippet

browser.Navigate("www.google.com")

and the event fired.


Turns out if you name the window it won't fire, but if you do:
Code Snippet

browser.Navigate("<url>",null,<data>,"Content-Type: application/x-www-form-urlencoded");

it will fire.

a__ryan___  Thursday, October 16, 2008 11:04 PM

You can use google to search for other answers

Custom Search

More Threads

• Restoring the UI (width) changes in datagrid after refresh
• Identity permission in winform app
• Can't get flowLayoutPanel to show usercontrol properly.
• Set SingleMonthSize
• problem in closing a form ????????
• Strings with bounded value in a textbox. (To recipient box in Outlook Mail)
• Saving Settings and Refresh Main Form
• textproblem
• Get rid of button style but keep behavior
• How to stop ordering of rows in datagridview by clicking on column of datagridview?