Problem with Webbrowser control....

  • Thread starter Thread starter Jim Hubbard
  • Start date Start date
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!
 
Oops.....this may be important.

The error occurs on the line that reads...."doc.body.innerHTML =
HTMLString.ToString".
 
Seems that navigating to any URL (even "about:blank") before using the
innerHTML object eliminates the problem...
 
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
 
Back
Top