1
Answer

webBrowser control throws exception

Roger Garrett

Roger Garrett

13y
2.7k
1
I'm writing a C# program that makes use of the webBrowser control. Generally I've been successful in using it but have encountered a problem I can't figure out.

I intercept the DocumentCompleted event from my webBrowser control. During the processing of that event I create an additional webBrowser control and  call its Navigate function to tell it to navigate to a specific URL. When I do that it throws an exception : "IWebBrowser2 get from the native ActiveX control did not succeed", and I can see that the axIWebBrowser2 property of the control is null.
My code is approximately like this:

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
 webBrowser newWebBrowser = new webBrowser();
  try
  {
     newWebBrowser.Navigate("http://www.somewebsite.com");
  }
  catch
  {
    MessageBox.Show("Excption was thrown!");
  }
}
 
Is it possible that you can't instantiate and call the Navigate method for a webBrowser while processing the DocumentCompleted event for another webBrowser control?
Answers (1)