I have created an windows application which loads a web page. I need to check the page load time of the web page. I cannot use a timer and note the time at document completed event because the page is redirecting to some other page and it has lots of iframes as well so the document completed event fires many times ( around 10). So how to know that the page has completed loading? I can count the number of document completed events on that page and then stop the timer when it is called for the last time. But I want a generic method. Please guide me regarding this.
Hi kevin Dark:
I think I know your questions now. You mean when you load a website page with using webBrowser, the page redirects may times and you just want to know when the last page is loaded complete.
So, we can use DocumentCompleted event to tell us as below:
private void webBrowser1_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e)
if (webBrowser1.ReadyState == WebBrowserReadyState .Complete)
this .textBox1.Text = webBrowser1.Document.Url.ToString(); //each redirect url may be shown
if (webBrowser1.Document.Url.ToString() == “the final url string” )
MessageBox .Show( “Load Complete!” );
If you have any questions, please feel free to tell us.
I use the url< http://www.live.com> to load by webbrowser and login in, when i sign out the live.com, it will redirect the “http://www.bing.com/” and I get the last redirection.
// Get the target
HtmlElement target = _webBrowser.Document.GetElementById(“somedivthatwillbepopulatedbytheajaxrequest”);
if (target != null)
target.AttachEventHandler(“onpropertychange”, new EventHandler(handler));
The event will fire whenever the element is (re)populated with HTML so all you do is implement the handler so you can check the InnerHTML or InnerText or whatever it is you need to do, and do it to your hearts content Wink
private void handler(Object sender, EventArgs e)
HtmlElement div = _webBrowser.Document.GetElementById(“somedivthatwillbepopulatedbytheajaxrequest”);
if (div == null) return;
String x = div.InnerHtml; // etc
if (!x.Equals(“Loading…”, StringComparison.InvariantCultureIgnoreCase))
// Now the element has been populated, do something