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;
}
}