Ask a Question related to ASP.NET Building Controls, Design and Development.
-
David Bowey #1
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
-
Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
I've created user controls that contain listboxes that are dynamically populated from the database. In the html view of the user control... -
[WebMethod] System.NullReferenceException: Object reference not set to an instance of an object.
Um, this isn't going to work, generally. Web services, as any web app (especially on Windows server 2003) are heavily sandboxed. The method you... -
Mysterious Error: Object reference not set to an instance of an object
Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception... -
HELP! Error Loading ASPX : Object Reference not set to an instance object
Hello, When i run my aspx i get this weird error: System.NullReferenceException: Object reference not set to an instance of an object. at... -
Object reference not set to an instance of an object. .......... Error .... Please Help
Hi, I am facing a problem, and i don't know why the error is being generated. I am updating a datagrid with an XML file. My code is ... -
David Bowey #2
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" <db@f.coz> wrote in message
news:O3yxLafKFHA.3500@TK2MSFTNGP14.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



Reply With Quote

