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

D

David Bowey

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
 
D

David Bowey

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

Thank you!!!
Dave

David Bowey said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top