FIX: Application Terminates When the Window.Close Method Is Used to Close the Web Page That Is Hosted in the Web Browser Control (816638)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

SYMPTOMS

When you close the HTML page that is hosted in the WebBrowser control in a Windows application by using the window.close method, the Windows application quits together with the HTML page.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual Studio .NET 2003.

MORE INFORMATION

Steps to Reproduce the Behavior

Create an HTML Page

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click File.
  3. Select General under Categories, and then select HTML Page underTemplates.
  4. Add an HTML Button control to the HTML page.
  5. Double-click the Button control, and add the following code in the Button1_Click event:
    window.close()
  6. Save the HTML page as C:\Test.html.
  7. Close the HTML page.

Create a Windows Application

  1. Create a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.
  2. Right-click the Toolbox, and then click Customize Toolbox.
  3. On the COM Components tab, click to select Microsoft Web Browser, and then click OK.
  4. Add a Button control to Form1.
  5. Add an Explorer control to Form1.
  6. Double-click the Button on Form1, and then add the following code in Button1_Click event handler:

    Visual Basic .NET Code
    AxWebBrowser1.Navigate2("C:\Test.html")
    Visual C# .NET Code
    object obj = null;
    axWebBrowser1.Navigate ("C:\\Test.html", ref obj, ref obj, ref obj, ref obj);
  7. On the Debug menu, click Start to run the application.
  8. On the Form1 form, click Button1 to load the Test.html page.
  9. Click Button on the Test.html page.
  10. Click Yes when you are prompted to close the window. You may notice that the Windows application quits.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

311298 BUG: The BeforeNavigate2 Event of the WebBrowser Control Does Not Fire If Hosted in a Visual Basic .NET Application


Modification Type:MajorLast Reviewed:10/1/2003
Keywords:kbCtrl kbWindowsForms kbControl kbfix KB816638 kbAudDeveloper