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.AxWe bBrowser (fiWebBrsr)) placed on it. There is a Before_Navigate 2 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.Interne tExplorer is created and passed the information from the BeforeNavigate2 Event 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:
To demonstrate and simplify the problem, I created a C# windows form project with only a windows web browser (AxShDocVW.AxWe bBrowser (fiWebBrsr)) placed on it. There is a Before_Navigate 2 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.Interne tExplorer is created and passed the information from the BeforeNavigate2 Event 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:
Code:
namespace Test
{
public partial class frmSrch : Form
{
public frmSrch()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
this.fiWebBrwsr.Navigate("http://oregon.jobing.com/");
}
private void fiWebBrwsr_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
if (!(e.postData == null))
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
ie.Visible = true;
ie.Navigate2(ref e.uRL, ref e.flags, ref e.targetFrameName,ref e.postData,ref e.headers);
e.cancel = true;
}
}
}
}