Thursday, March 22, 2012

Object reference not set to an instance of an object.

I get the error: Object reference not set to an instance of an object

With this code:

Dim test3 As New TextBox
test3 = CType(e.Item.FindControl("name"), TextBox)
Dim name As String = test3.Text

The specific line is:

Dim name As String = test3.Text

So, what do I need to do to fix that?

Thanks.Because e.Item.FindControl() does not find a control named as "name", hence
next line of code gives you that error.

You need to figure out why there is no TextBox, called "name" found.

"Jim in Arizona" <tiltowait@.hotmail.comwrote in message
news:ePOMLuz1GHA.4300@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I get the error: Object reference not set to an instance of an object
>
With this code:
>
Dim test3 As New TextBox
test3 = CType(e.Item.FindControl("name"), TextBox)
Dim name As String = test3.Text
>
The specific line is:
>
Dim name As String = test3.Text
>
So, what do I need to do to fix that?
>
Thanks.


Yep. That's it. Thanks. Now I have another question to post regarding
this whole mess, which I bet no one will have an answer for.

Thanks Norman.

Norman Yuan wrote:

Quote:

Originally Posted by

Because e.Item.FindControl() does not find a control named as "name", hence
next line of code gives you that error.
>
You need to figure out why there is no TextBox, called "name" found.
>
"Jim in Arizona" <tiltowait@.hotmail.comwrote in message
news:ePOMLuz1GHA.4300@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I get the error: Object reference not set to an instance of an object
>>
>With this code:
>>
> Dim test3 As New TextBox
> test3 = CType(e.Item.FindControl("name"), TextBox)
> Dim name As String = test3.Text
>>
>The specific line is:
>>
> Dim name As String = test3.Text
>>
>So, what do I need to do to fix that?
>>
>Thanks.


>
>

0 comments:

Post a Comment