Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,553 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,905 people online right now. Registration is fast and FREE... Join Now!




WebBrowser's Document Completed event

 
Reply to this topicStart new topic

WebBrowser's Document Completed event

itpro4470
18 Aug, 2008 - 04:05 PM
Post #1

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 120



Thanked: 1 times
Dream Kudos: 25
My Contributions
for some reason the DocumentCompleted event in my code is firing at a wierd place the line I surrounded by stars will trigger the the DocumentCompleted event I haven't found anything via google about this being a problem for others and this code causing that event to fire. Is there any way to overcome this?
CODE

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            switch (this.webPageCentury)
            {
                case 0:
                    //Get the HtmlDocument from the current web page
                    HtmlDocument webDoc = this.webBrowser1.Document;

                    //Pull out the elements we will need to use
                    HtmlElement loginBox = webDoc.All["login"];
                    HtmlElement passwordBox = webDoc.All["password"];
                    HtmlElement submitButton = webDoc.All["submit"];

                    //Check to see if the login box contains the user name. If it does just click submit. If not get the username and password of the user
                    while (loginBox.GetAttribute("value") == "")
                    {
                        SignIn signInBox = new SignIn();
                        signInBox.ShowDialog();
                        loginBox.SetAttribute("value", GlobalSettings.userName);
                        passwordBox.SetAttribute("value", GlobalSettings.password);

                    }
                    submitButton.InvokeMember("click");
                    this.webPageCentury++;
                    break;
                case 1:
                    

                    //Grab the source
                    StringBuilder sourceOne = new StringBuilder(this.webBrowser1.DocumentText);

                    //check for the function changeit
                    if (sourceOne.ToString().Contains("function"))
                    {
                        this.webBrowser1.Navigate(@"http://www.somepage.com/someotherhtmlfile");
                        this.webPageCentury++;
                    }
                    else
                    {
                        this.webBrowser1.Navigate(@"http://www.somepage.com");
                        this.webPageCentury--;
                    }
                    break;
                case 2:
                    
                    HtmlDocument parseThis = this.webBrowser1.Document;
                    HtmlElementCollection tdTags = parseThis.GetElementsByTagName("tr");
                    foreach (HtmlElement hElement in tdTags)
                    {
                        if (hElement.All["td"].InnerText.Contains("targettext")
                        {
                     **** this.emailsToSend[this.emailsCount] = new StringBuilder(hElement.All["td"].InnerText); *****
                        }
                    }
                    break;

            }
        }

User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: WebBrowser's Document Completed Event
20 Aug, 2008 - 06:11 AM
Post #2

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
That is really weird.
Why don't you try:
CODE

//this.emailsToSend[this.emailsCount] = new StringBuilder(hElement.All["td"].InnerText);


If it is still firing the event then you know it is not that line of code doing the firiing.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:17PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month