Home All Groups Group Topic Archive Search About

problems with URL value in webbrowser app

Author
2 Mar 2006 4:32 PM
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

Author
2 Mar 2006 8:00 PM
Armin Zingler
Show quote Hide quote
"Randall Arnold" <randall.nospam.arnold@nokia.com.> schrieb
> 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
Author
2 Mar 2006 10:32 PM
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

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:ODoXxWjPGHA.1216@TK2MSFTNGP14.phx.gbl...
> "Randall Arnold" <randall.nospam.arnold@nokia.com.> schrieb
>> 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
>