carnick carnick - 5 months ago 8x Question Webbroswer strange occurence

I have a webbrowser control that goes to a website and logs in automatically. It works just fine even when someone enters a wrong password in the form. but once the right password is entered after a wrong password, the login form pops up a second time and they have to enter the user/password again and it will work the second time around. I have included the full code for the webbrowser form. Another weird thing that happens when this same issue above happens is it will pop up a default browser to the url listed but with this at the end http://url%20-%20#b8716a8
Any ideas?

Imports System.IO
Imports Microsoft.Win32
Public Class frm_webbrowser
Private cntAttempts1 = 0
Private Const BrowserKeyPath As String = "\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"

Private Sub frm_webbrowser_Load(sender As Object, e As EventArgs) Handles MyBase.Load

WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate(“url", "_top", Nothing, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36")

End If
End Sub

Private Sub frm_webbrowser_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
End Sub

Private Sub CreateBrowserKey(Optional ByVal IgnoreIDocDirective As Boolean = False)
Dim basekey As String = Microsoft.Win32.Registry.CurrentUser.ToString
Dim value As Int32
Dim thisAppsName As String = My.Application.Info.AssemblyName & ".exe"

Select Case (New WebBrowser).Version.Major
Case 8
If IgnoreIDocDirective Then
value = 8888
value = 8000
End If
Case 9
If IgnoreIDocDirective Then
value = 9999
value = 9000
End If
Case 10
If IgnoreIDocDirective Then
value = 10001
value = 10000
End If

Case 11
If IgnoreIDocDirective Then
value = 11001
value = 11000
End If
Case Else
Exit Sub
End Select
Microsoft.Win32.Registry.SetValue(Microsoft.Win32.Registry.CurrentUser.ToString & BrowserKeyPath,
Process.GetCurrentProcess.ProcessName & ".exe",
End Sub

Private Sub RemoveBrowerKey()
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(BrowserKeyPath.Substring(1), True)
key.DeleteValue(Process.GetCurrentProcess.ProcessName & ".exe", False)
End Sub

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

WebBrowser1.Document.GetElementById("username").SetAttribute("value", user.Text)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", pass.Text)

cntAttempts1 += 1

If cntAttempts1 = 3 Then
cntAttempts1 = 0
MsgBox("Invalid username/password please re-enter.")
Dim box = New frm_weblogin()
End If

End Sub
Private Sub WebBrowser1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
End Sub


If anyone else is interested I was able to fix this by putting the following code in the DocumentCompleted.

If e.Url.AbsolutePath <> TryCast(sender, WebBrowser).Url.AbsolutePath Then
End If

The weird pop up I was getting in my default browser was caused by the MsgBox so I just removed it and created a form that said the username/password was invalid and had the login fields.