Thursday, March 22, 2012

Object reference not set to an instance of an object.

Hello,

I have a user control that contains a datalist and within that a asp label,
as follows:

<asp:DataList ID="dlHomeDetail_Starters" Runat="server" CellPadding="1"
CellSpacing="1" Width="100%" RepeatDirection="Vertical" RepeatColumns="1">
<HeaderTemplate>
<tr class=mainhead vAlign=center>
<td class=away colSpan=5><asp:Label ID="lblGroupName"
Runat="server"></asp:Label></td>
</tr>
<tr class=bg1 align=middle
In my code behind, in the page load event I am receiving this error "Object
reference not set to an instance of an object" on this line
lblGroupName.Text = "Test".

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

lblGroupName.Text = "Test"

dlHomeDetail_Starters.DataSource =
oFFLLeague.getPlayerStats_TeamSummary(Session("FFLLeagueID"),
Request.Params("week"),
oFFLLeague.getHomeTeamIDFromGameID(Request.Params( "week"),
Request.Params("gid")), "Starters")
dlHomeDetail_Starters.DataBind()

End Sub

Is my problem due to the sequence of events in the webform page load and
that the label is not yet available? I always find understanding the order
of events confusing when using a user control.

Any help is appreciated,
Thanks ChrisUsually when you get the error it is because of a type
mismatch. But things that I see in your code are that you
seem to be calling databind without filling your dataset
with a data adapter?

>--Original Message--
>Hello,
>I have a user control that contains a datalist and within
that a asp label,
>as follows:
> <asp:DataList ID="dlHomeDetail_Starters" Runat="server"
CellPadding="1"
>CellSpacing="1" Width="100%" RepeatDirection="Vertical"
RepeatColumns="1">
> <HeaderTemplate>
> <tr class=mainhead vAlign=center>
> <td class=away colSpan=5><asp:Label ID="lblGroupName"
>Runat="server"></asp:Label></td>
> </tr>
> <tr class=bg1 align=middle>
>In my code behind, in the page load event I am receiving
this error "Object
>reference not set to an instance of an object" on this
line
>lblGroupName.Text = "Test".
> Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As
>System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> lblGroupName.Text = "Test"
> dlHomeDetail_Starters.DataSource =
>oFFLLeague.getPlayerStats_TeamSummary(Session
("FFLLeagueID"),
>Request.Params("week"),
>oFFLLeague.getHomeTeamIDFromGameID(Request.Params( "week"),
>Request.Params("gid")), "Starters")
> dlHomeDetail_Starters.DataBind()
> End Sub
>Is my problem due to the sequence of events in the
webform page load and
>that the label is not yet available? I always find
understanding the order
>of events confusing when using a user control.
>Any help is appreciated,
>Thanks Chris
>
>.
Your data-bound control results in multiple label
controls, not just one.

you need to go through the rows of the resulting control
to find the label you want, or use findControl or any
other number of ways to navigate the control structure.
>--Original Message--
>Hello,
>I have a user control that contains a datalist and within
that a asp label,
>as follows:
> <asp:DataList ID="dlHomeDetail_Starters" Runat="server"
CellPadding="1"
>CellSpacing="1" Width="100%" RepeatDirection="Vertical"
RepeatColumns="1">
> <HeaderTemplate>
> <tr class=mainhead vAlign=center>
> <td class=away colSpan=5><asp:Label ID="lblGroupName"
>Runat="server"></asp:Label></td>
> </tr>
> <tr class=bg1 align=middle>
>In my code behind, in the page load event I am receiving
this error "Object
>reference not set to an instance of an object" on this
line
>lblGroupName.Text = "Test".
> Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As
>System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> lblGroupName.Text = "Test"
> dlHomeDetail_Starters.DataSource =
>oFFLLeague.getPlayerStats_TeamSummary(Session
("FFLLeagueID"),
>Request.Params("week"),
>oFFLLeague.getHomeTeamIDFromGameID(Request.Params( "week"),
>Request.Params("gid")), "Starters")
> dlHomeDetail_Starters.DataBind()
> End Sub
>Is my problem due to the sequence of events in the
webform page load and
>that the label is not yet available? I always find
understanding the order
>of events confusing when using a user control.
>Any help is appreciated,
>Thanks Chris
>
>.

0 comments:

Post a Comment