469,632 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

How to control number of instances of Internet Explorer Created

I have been trying to get an instance of internet explorer to navigate to a website using the Navigate2 command. When the navigation request uses the Get method (just a URL) there is no problem. However, when the navigation involves the post method two instances of internet explorer are created. One of the instances is uninitialized while the other correctly navigates to the site. I need to have only one instance created and have it navigate properly.

To demonstrate and simplify the problem, I created a C# windows form project with only a windows web browser (AxShDocVW.AxWebBrowser (fiWebBrsr)) placed on it. There is a Before_Navigate2 event on the form that determines if there is an Post data associated with the Navigate2 event. If Post data exists, a new instance of SHDocVw.InternetExplorer is created and passed the information from the BeforeNavigate2Event arguments and directed to navigate to the same web site. What is observed is that two instances of an internet explorer will be created. One will successfully navigate to the website indicated. The other one will be tracked by the code but it will be uninitialized. This is the problem I'm trying to resolve. How can the second instance of the internet explorer be prevented and the one being tracked by the code be caused to navigate to the website. I'm using Visual Studio 2008, Internet Explorer 7 and the project is in C#. The code that is associated with the form is shown below:

Expand|Select|Wrap|Line Numbers
  1. namespace Test
  2. {
  3.   public partial class frmSrch : Form
  4.   {
  5.     public frmSrch()
  6.     {
  7.       InitializeComponent();
  8.     }
  9.  
  10.     private void Form1_Shown(object sender, EventArgs e)
  11.     {
  12.       this.fiWebBrwsr.Navigate("http://oregon.jobing.com/");
  13.     }
  14.  
  15.     private void fiWebBrwsr_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
  16.     {
  17.       if (!(e.postData == null))
  18.       {
  19.         SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
  20.         ie.Visible = true;
  21.         ie.Navigate2(ref e.uRL, ref e.flags, ref e.targetFrameName,ref e.postData,ref e.headers);
  22.         e.cancel = true;
  23.       }
  24.     }
  25.   }
  26. }
  27.  
Sep 30 '10 #1
0 1330

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Adam Stirk | last post: by
1 post views Thread by Wayne Gibson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.