How to tell when AxWebBrowser1 is finished loading?

I'm using VB.NET and I've got a button on a form with a webbrowser control on it.
On Form load it navigates to a site and logs in and goes to a specific page after login.
My goal is to click the button and then when the page finishes loading run some code to fill in the form.
I've already used "Private Sub AxWebBrowser1_DocumentComplete()" to auto negotiate past some other url's so the way I have it set up I cant really use it to tell when this page is done loading, so I have to find another way.

I've tried this but my "While" readystate part doesnt seem to work like it should.

How could I accomplish this?

   
Code:Private Sub btnFillCreditInquiry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFillCreditInquiry.Click
        AxWebBrowser1.Navigate2("https://www.MYSITE.com/creditbureau/CBRequest.asp?newreq=yes")

        While AxWebBrowser1.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_LOADING
            Application.DoEvents()
        End While

        If AxWebBrowser1.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE Then
            AxWebBrowser1.Document.Frames("Main").document.Forms(0)("app_first_name").Value = "FirstName"
        End If

    End Sub
 


The following is my DOCUMENTCOMPLETE code that makes it hard to use for the previous button click code.
--------------------------CODE -----------------------------------
   Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxWebBrowser1.DocumentComplete
        Static page As Integer = 1
        Select Case page
            Case 1
                AxWebBrowser1.Document.Forms("login").username.value = myLogin
                AxWebBrowser1.Document.Forms("login").password.value = myPassword
                AxWebBrowser1.Document.Forms("login").submit()

                page = page + 1     ' add one to the counter so it = 2

            Case 2
                AxWebBrowser1.Navigate2("https://www.MYSITE.com/applications/loan_app/appv2_start.asp?start=Y")

                page = page + 1     ' add one to the counter so it = 3

            Case 3
                Exit Sub
        End Select
    End Sub
LVL 1
Matrix1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jacobhooverCommented:
Easy, create a public Property or member vairable in the AxWebBrowser class that tells you when the application is ready.

IE, add :
Public blnIsReady as Boolean = False
in the class definition, then in the AxWebBrowser1_DocumentComplete once all of your pages are loaded (case 3 at the moment) add:
Me.blnIsReady = True

Then in the containing class your loop would be:
        While AxWebBrowser1.blnIsReady = False
            Application.DoEvents()
        End While
I would also suggest a call to something similar to the Sleep API call, as the tight loop with just DoEvents in it is a waste of the CPU.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.