Problem with Webbrowser control....

J

Jim Hubbard

When using the following code.....

------------------------------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim HTMLString As String

HTMLString = TextBox1.Text

Dim doc As mshtml.HTMLDocument = AxWebBrowser1.Document()
doc.body.innerHTML = HTMLString.ToString

End Sub
------------------------------------

I get the following error....

------------------------------------
An unhandled exception of type 'System.NullReferenceException' occurred in
InetTesting.exe

Additional information: Object reference not set to an instance of an
object.
------------------------------------


I don't understand what this error is telling me I need to do. (No that
Microsoft errors are cryptic or anything.....)

Thanks for your help!
 
J

Jim Hubbard

Oops.....this may be important.

The error occurs on the line that reads...."doc.body.innerHTML =
HTMLString.ToString".
 
J

Jim Hubbard

Seems that navigating to any URL (even "about:blank") before using the
innerHTML object eliminates the problem...
 
C

Charles Law

Hi Jim

This is by design. The WebBrowser control must be initialised correctly
before you have access to the DOM. The usual way is to navigate to
about:blank, even if you intend to navigate somewhere else straight
afterwards.

Also, when you have navigated to about:blank the first time, make sure you
wait for the readystate to go to "complete", otherwise the control will not
be correctly initialised.

HTH

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top