Microsoft KB Archive/816638

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

Article ID: 816638

Article Last Modified on 10/1/2003

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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.



Create an HTML Page
 Start Visual Studio .NET. On the File menu, point to New, and then click File. Select General under Categories, and then select HTML Page underTemplates. Add an HTML Button control to the HTML page.  Double-click the Button control, and add the following code in the Button1_Click event: window.close  Save the HTML page as C:\Test.html .</li> Close the HTML page.</li></ol>

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

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

<div class="references_section">