Friday, March 16, 2012

Object reference not set to an instance of an object. - Label

I am gettign the above error. My source errors out here:

Line 11: 'check if phone is listed to the public
Line 12: 'if not listed change label to warn user
Line 13: If CType(e.Item.FindControl("UnlistedLabel"), Label).Text = "True" Then
Line 14: CType(e.Item.FindControl("lblUnlisted"), Label).Visible = True
Line 15: End If

Full Sub Code:

Protected Sub DataList1_ItemDataBound(ByVal senderAs Object,ByVal eAs DataListItemEventArgs)
'check if phone is listed to the public
'if not listed change label to warn user
If CType(e.Item.FindControl("UnlistedLabel"), Label).Text ="True"Then
CType(e.Item.FindControl("lblUnlisted"), Label).Visible =True
End If
End Sub

Why is this happening, and weirded yet, it worked about 30 times until I restarted my computer. I have read and googled lots and seems like I should be able to called directly, but perhaps I need declare my labels first?

Any help would be appreciated.

I think you may have the variable names wrong, in one instance you search for "UnlistedLabel" and in the second you search for "lblUnlisted", I assume these are meant to reference the same object?

Thanks

Amar

0 comments:

Post a Comment