Well, I\'m using a simple webbrowser control to browse to a page, so I need to change the Text of the form while doing so. I\'m using -
private void webBrow
If firing twice is a problem then this should work:
string body="";
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (body == webBrowser1.Document.Body.InnerHtml) return;
body = webBrowser1.Document.Body.InnerHtml;
// Here is something you want
}
Actually, it doesn't always get fired. Haven't figured out why not. I have a timer and just check the ReadyState repeatedly for a few minutes. (Using embedded browser control).
Every time a frame loads, the event is fired.
Also, before you even go there, the IsBusy
property will only be True
whilst the first frame has not loaded.
void BrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
return;
//The page is finished loading
}
How To Determine When a Page Is Done Loading in WebBrowser Control
DocumentCompleted
is WinForms' wrapper of the DocumentComplete evert, however WebBrowserDocumentCompletedEventArgs hides the sender parameter so you cannot tell which frame is raising the event.
Alternatively you can check WebBrowser.ReadyState
.
You can check the WebBrowser.ReadyState when the event is fired:
if (browser.ReadyState != WebBrowserReadyState.Complete)
return;
ReadyState will be set to Complete once the whole document is ready.
Might be you are subscribing this event multiple times like in your some method when your navigating to URL everytime you subscribe to this event.
To solve this problem, move that line out of the method and put it somewhere else where it will only be called once per instance. In the constructor of the class perhaps... That should solve your problem .