Professional Web Applications Themes

Custom Control Problem :: Object reference not set to an instance of an object - ASP.NET Building Controls

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.WebUserControl 1" 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 ...

  1. #1

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

    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.WebUserControl 1"
    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_Loa d(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 Guest

  2. #2

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

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

    Thank you!!!
    Dave

    "David Bowey" <dbf.coz> wrote in message
    news:O3yxLafKFHA.3500TK2MSFTNGP14.phx.gbl...
    > 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.WebUserControl 1"
    > 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_Loa d(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 Guest

Similar Threads

  1. Replies: 2
    Last Post: June 6th, 04:02 PM
  2. Replies: 0
    Last Post: March 7th, 11:28 PM
  3. Replies: 13
    Last Post: January 4th, 02:37 PM
  4. Replies: 0
    Last Post: July 25th, 10:42 AM
  5. Replies: 2
    Last Post: July 9th, 02:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139