• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

Problem with Page.LoadControl --- Object reference not set to an instance of an object.

Hello,

I have the following code and for some reason it is not working.  In another application it works perfectly, but not this one.

default.aspx.vb
-----------------------------------
Public Class _default
    Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim control As Control
        control = Page.LoadControl("UserControls/LoginScreen.ascx")
        LoginCell.Controls.Add(control)  <------------------ Problem occurs here!
    End Sub
End Class

LoginScreen.ascx.vb
------------------------------------
Public MustInherit Class LoginScreen
    Inherits System.Web.UI.UserControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


I keep getting the error: Object reference not set to an instance of an object.

Thanks in advance.
0
attipa
Asked:
attipa
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
What is Nothing?  LoginCell?  control?

Bob
0
 
attipaAuthor Commented:
LoginCell is the ID of the column in the table that the UserControl, LoginScreen.ascx needs to load in to.

<td ID="LoginCell" runat=server>
0
 
Bob LearnedCommented:
At that point, though, in the code, is LoginCell nothing?  Or is control nothing?

Bob
0
 
attipaAuthor Commented:
i dont know where it is happening....but for some reason, now its working.  you get the points anyway.
0
 
Bob LearnedCommented:
I suspect that LoginCell was nothing, because I have seen that bug a few times.  It can get recreated in code, so it is self-healing.

Bob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now