Object reference not set to an instance of an object.

Discussion in 'ASP .Net' started by Chris Fink, Jul 3, 2003.

  1. Chris Fink

    Chris Fink Guest

    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
     
    Chris Fink, Jul 3, 2003
    #1
    1. Advertising

  2. Usually 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
    >
    >
    >.
    >
     
    Terry Orzechowski, Jul 3, 2003
    #2
    1. Advertising

  3. Chris Fink

    David Waz... Guest

    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
    >
    >
    >.
    >
     
    David Waz..., Jul 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    695
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,388
    Anushi
    Jul 29, 2004
  3. yysiow
    Replies:
    1
    Views:
    436
    Kevin Spencer
    Jul 12, 2003
  4. Tim
    Replies:
    1
    Views:
    497
    Bill Priess
    Jul 17, 2003
  5. Replies:
    1
    Views:
    482
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page