1

I have a form with a browser control. (this control uses IE9 because I set values on registry editor)

This web browser navigates to a specific URL and fills all fields on HTML page and submit them, then result page is displayed. My problem is that i just want to know when this reslut page is fully loaded or completed so that i can fetch some information. I use WebBroswer_DocumentCompleted event which works fine for the first page but not for the result page as it triggers before result page is loaded.

I tried other solution which is to check the div tag inside the result page (this tag only appears when result page is loaded completely) and it works but not always.

My code:

private void WebBroswer_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    { 

        HtmlElementCollection elc3 = this.BotBrowser.Document.GetElementsByTagName("div");
        foreach (HtmlElement el in elc3)
        {
            if (el.GetAttribute("id").Equals("Summary_Views")) //this determine i am at the result page
            {
               // fetch the result
            }
        }}

That div id is "Summary_Views". I can provide you the link of that website on demand which is just for BLAST tools and database website for research purpose.

Saad Qureshi
  • 389
  • 4
  • 19

3 Answers3

1

Frames and IFrames will cause this event to fire multiple times. Check out this answer:
HTML - How do I know when all frames are loaded?

Or this answer:
How to use WebBrowser control DocumentCompleted event in C#?

Or ms's kb article: http://support.microsoft.com/kb/180366

Community
  • 1
  • 1
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
1

Do you know if there are frames? If so then please say so, so people can help with that. If not then say so, so people can offer alternatives.

My guess is that the content is being generated by JavaScript. If it is then the document is complete before the JavaScript executes and you need to somehow wait until the JavaScript is done. The solution depends upon the web page. So you might need to process multiple document completes for diagnostic purposes and attempt to determine if there is a way to know which one you need.

Sam Hobbs
  • 83
  • 1
  • 6
  • I agree with you so I think I should wait for the page to be fully loaded even after the DocumentComplted event is fired. So how i can wait? I use Thread.Sleep() function but it stops the whole loading of page and code too. – Saad Qureshi Sep 26 '12 at 15:30
  • I have made a function for finding this Div tag and assinged this function to a new thread(by using ThreadStart delegate) .I just want to start this new thread and make it sleep for some seconds after DocumentCompleted event is fired for result page so that I can find Div tag easily. – Saad Qureshi Sep 29 '12 at 11:48
  • I am relatively new to Stackoverflow so I did not notice this reply before. There is a very simple way to create a handler for the DocumentComplete event; just double-click on the WebBrowser control in the designer. The DocumentComplete event is the default event in the designer for the WebBrowser control. – Sam Hobbs Oct 23 '12 at 15:08
  • Yes i did this already. But my problem was that this event was being fired 2 times for each page load but the main pain was that this event was fired more earlier then result page is loaded completely. But now i have solved my problem already and my genetic research purpose bot did his work very well :) – Saad Qureshi Nov 11 '12 at 10:31
1

At last i have solved my problem. I put a timer control from toolbox and set its time interval to 200ms and its Autoreset property to false. I set a tick event which has a code to check every 200ms whether this Div has been loaded or not, after that, Autoreset property is set to true.This solution is working perfectly :)

Saad Qureshi
  • 389
  • 4
  • 19