problems with URL value in webbrowser app

R

Randall Arnold

I'm creating a VB 2005 Express app that hosts the webbrowser control. Everything works well except one area: the Navigating event.

In that event, I need to evaluate the URL property of the webbrowser object. The URL is set beforehand in the browser object. I'm using Webbrowser1.URL.ToString to check it. However, I get the following error when I try this:

"A first chance exception of type 'System.NullReferenceException' occurred in (my program name)"

I created a test conditional to evaluate the URL property, as so:

If IsDBNull(Webbrowser1.Url) Then
MsgBox("null url")
Else
MsgBox("not null url")
End If
The result is that the URL is not null-- yet I get the error message above anyway!

Any clues on how to handle this?

Thanks,

Randall Arnold
 
A

Armin Zingler

Randall Arnold said:
I'm creating a VB 2005 Express app that hosts the webbrowser
control. Everything works well except one area: the Navigating
event.

In that event, I need to evaluate the URL property of the webbrowser
object. The URL is set beforehand in the browser object. I'm using
Webbrowser1.URL.ToString to check it. However, I get the following
error when I try this:

"A first chance exception of type 'System.NullReferenceException'
occurred in (my program name)"

I created a test conditional to evaluate the URL property, as so:

If IsDBNull(Webbrowser1.Url) Then
MsgBox("null url")
Else
MsgBox("not null url")
End If
The result is that the URL is not null-- yet I get the error message
above anyway!

Any clues on how to handle this?


Why IsDBNull? The type of System.Windows.Forms.WebBrowser.Url is System.Uri.
It can /never/ be DBNull.Value. DBNull.Value is stored only in a database.

If you would want to know whether a property references an object, check for
Nothing:

If webbrowser1.url is nothing then


If I use

txtUrl.Text = WebBrowser1.Url.ToString

to display the new url, I never get a NullReferenceException. Do you have a
public URL that I can use to repro the problem?


Armin
 
R

Randall Arnold

Ok, forget the Null test, as it turned out to be moot. The problem is in
Webbrowser1.URL.ToString . It won't do any good to post a url, and here's
why: that same bit of code works fine in the DocumentComplete and Navigated
events. It just bombs in the Navigating event-- but I still need to
evaluate it there...

Randall Arnold
 

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