Custom Control Problem :: Object reference not set to an instance of an object

Discussion in 'ASP .Net Web Controls' started by David Bowey, Mar 16, 2005.

  1. David Bowey

    David Bowey Guest

    Hi All!

    I have the following Custom Control file...

    '########### WebUserControl1.ascx #############

    <%@ Control Language="vb" AutoEventWireup="false"
    Codebehind="WebUserControl1.ascx.vb"
    Inherits="nmasoft.vevo.web.controls.WebUserControl1"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    <asp:Literal id="Literal2" runat="server"></asp:Literal>

    '########### END WebUserControl1.ascx #############

    '########### WebUserControl1.ascx.vb ###########

    Public Class WebUserControl1
    Inherits System.Web.UI.UserControl

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub
    Protected WithEvents Literal2 As System.Web.UI.WebControls.Literal

    'NOTE: The following placeholder declaration is required by the Web Form
    Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    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
    Literal2.Text = "Hello World"
    End Sub

    End Class

    '########### END WebUserControl1.ascx.vb ###########

    I've compiled the Custom Control into DLL and placed the DLL in the Bin
    directory of my web site. After that I've declared the control with
    @Register directive at the top of the ASPX page and I put the control on the
    ASPX page.

    After that, when I browse it in the Browser, I get...

    ######### ERROR MESSAGE #############

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web
    request. Information regarding the origin and location of the exception can
    be identified using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an
    object.]
    nmasoft.vevo.web.controls.WebUserControl1.Page_Load(Object sender,
    EventArgs e)
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Control.LoadRecursive() +98
    System.Web.UI.Page.ProcessRequestMain() +750

    ######### END ERROR MESSAGE #############

    What did I do wrong? Or didn't do?!

    On side note, If I comment out the code in the Page_Load of the
    WebUserControl1, the web page renders without any errors. But of course, it
    defeats the purpose of the Custom Control :p

    So I think the reason it is raising "Object Reference Not Set" is that
    somehow Literal1 in WebUserControl1 must be null. But I don't know why.

    Thank you all in advance!!
    Dave
    David Bowey, Mar 16, 2005
    #1
    1. Advertising

  2. David Bowey

    David Bowey Guest

    Somebody please help!! This problem is getting me no where!

    Thank you!!!
    Dave

    "David Bowey" <> wrote in message
    news:...
    > Hi All!
    >
    > I have the following Custom Control file...
    >
    > '########### WebUserControl1.ascx #############
    >
    > <%@ Control Language="vb" AutoEventWireup="false"
    > Codebehind="WebUserControl1.ascx.vb"
    > Inherits="nmasoft.vevo.web.controls.WebUserControl1"
    > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    > <asp:Literal id="Literal2" runat="server"></asp:Literal>
    >
    > '########### END WebUserControl1.ascx #############
    >
    > '########### WebUserControl1.ascx.vb ###########
    >
    > Public Class WebUserControl1
    > Inherits System.Web.UI.UserControl
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub
    > InitializeComponent()
    >
    > End Sub
    > Protected WithEvents Literal2 As System.Web.UI.WebControls.Literal
    >
    > 'NOTE: The following placeholder declaration is required by the Web
    > Form Designer.
    > 'Do not delete or move it.
    > Private designerPlaceholderDeclaration As System.Object
    >
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Init
    > 'CODEGEN: This method call is required by the Web Form Designer
    > 'Do not modify it using the code editor.
    > InitializeComponent()
    > End Sub
    >
    > #End Region
    >
    > 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
    > Literal2.Text = "Hello World"
    > End Sub
    >
    > End Class
    >
    > '########### END WebUserControl1.ascx.vb ###########
    >
    > I've compiled the Custom Control into DLL and placed the DLL in the Bin
    > directory of my web site. After that I've declared the control with
    > @Register directive at the top of the ASPX page and I put the control on
    > the ASPX page.
    >
    > After that, when I browse it in the Browser, I get...
    >
    > ######### ERROR MESSAGE #############
    >
    > Object reference not set to an instance of an object.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution of the current
    > web request. Information regarding the origin and location of the
    > exception can be identified using the exception stack trace below.
    >
    > Stack Trace:
    >
    >
    > [NullReferenceException: Object reference not set to an instance of an
    > object.]
    > nmasoft.vevo.web.controls.WebUserControl1.Page_Load(Object sender,
    > EventArgs e)
    > System.EventHandler.Invoke(Object sender, EventArgs e) +0
    > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > System.Web.UI.Control.LoadRecursive() +35
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Control.LoadRecursive() +98
    > System.Web.UI.Page.ProcessRequestMain() +750
    >
    > ######### END ERROR MESSAGE #############
    >
    > What did I do wrong? Or didn't do?!
    >
    > On side note, If I comment out the code in the Page_Load of the
    > WebUserControl1, the web page renders without any errors. But of course,
    > it defeats the purpose of the Custom Control :p
    >
    > So I think the reason it is raising "Object Reference Not Set" is that
    > somehow Literal1 in WebUserControl1 must be null. But I don't know why.
    >
    > Thank you all in advance!!
    > Dave
    >
    David Bowey, Mar 16, 2005
    #2
    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. Michael Meckelein
    Replies:
    3
    Views:
    9,295
    Kevin Spencer
    Apr 14, 2004
  2. Replies:
    1
    Views:
    477
    Mark Rae [MVP]
    Sep 20, 2007
  3. David Bowey
    Replies:
    1
    Views:
    246
    David Bowey
    Mar 16, 2005
  4. egi
    Replies:
    1
    Views:
    208
  5. gishani ratnayake via .NET 247

    User Control Error : Object reference not set to an instance of an object.

    gishani ratnayake via .NET 247, Mar 11, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    172
Loading...

Share This Page