Microsoft KB Archive/269614

= BUG: NavigateComplete Event Does Not Fire When WebBrowser Is Invisible =

Article ID: 269614

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q269614



SYMPTOMS
When you host an invisible WebBrowser control in your application, the NavigateComplete event does not fire after the first navigation. In addition, NavigateComplete does not navigate to another page when you use the navigate method. (This problem does not occur with Internet Explorer 5.01.)



RESOLUTION
To resolve this problem, rather than make the WebBrowser control invisible, you can position the WebBrowser control so that it does not display its user interface on its container window. To do this, you can set the Left property of the WebBrowser control equal to the negative of the control's Width property. Alternatively, you can put the WebBrowser control behind other controls in your application.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 In Microsoft Visual Basic, create a new Standard EXE project. In the Toolbox, add a component reference to Microsoft Internet Control. Add a WebBrowser control, a text box, and three buttons to the default form, Form1.  Copy the following code into the code module of Form1: Option Explicit Private Sub Command1_Click WebBrowser1.Navigate2 Text1.Text End Sub

Private Sub Command2_Click WebBrowser1.Visible = Not WebBrowser1.Visible End Sub

Private Sub Command3_Click MsgBox WebBrowser1.LocationURL End Sub

Private Sub Form_Load WebBrowser1.Visible = False Text1.Text = &quot;http://www.microsoft.com&quot; Command1.Caption = &quot;Navigate&quot; Command2.Caption = &quot;Make Visible&quot; Command3.Caption = &quot;Current_URL&quot; End Sub

Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) MsgBox &quot;BeforeNavigate Event&quot; End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant) MsgBox &quot;NavigateComplete Event&quot; End Sub  Press the F5 key to run the project. Click Navigate. Both the BeforeNavigate event message box and the NavigateComplete event message box appear.</li> In the text box, type another URL such as http://msdn.microsoft.com. The message box for the BeforeNavigate event appears, but the message box for the NavigateComplete event does not.</li> Click Make Visible to show the WebBrowser control, or click Current_URL. The current page remains at http://www.microsoft.com.</li></ol>

<div class="references_section">