0

I have working on windows application in the VS 2010 C#. I have used a Web Browser in my project. My application woks fine till the last week, but i found some problem in that Document Completed event.

Please see my code below.

  private void HomeBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (HomeBrowser.ReadyState == WebBrowserReadyState.Complete)
        {
            if (HomeBrowser.Document != null)
            {
                ...............................

please see the first if condition in my code. if this condition is not satisfied

rest of the code is not working. I don't know what happened.

Any Idea. Would you please help me as soon as possible.

Sajith
  • 856
  • 4
  • 19
  • 48
Ragesh P Raju
  • 3,879
  • 14
  • 101
  • 136
  • 2
    I suggest you handle DOM `onload` event and not rely upon `WebBrowser.ReadyState`. E.g.: http://stackoverflow.com/a/18370524/1768303 – noseratio Nov 19 '13 at 13:35

1 Answers1

2

In this case you don't need validate if the ReadyState is completed because the document completed event will execute when the browser has finished.

private void Form1_Load(object sender, EventArgs e)
    {
        this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
        this.webBrowser1.Navigate(new Uri("http://www.amazon.com"));
    }
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (this.webBrowser1.Document != null)
        {
            //Your code ...                
        }
    }