Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Error on a user control.

Reply
Thread Tools

Error on a user control.

 
 
Christopher Young
Guest
Posts: n/a
 
      10-20-2003
Here is my error. I have tried something similar in a
larger application I am working on and got similar
results. Thanks for any help in advance.

Server Error in '/WebApplication3' Application.
----------------------------------------------------------
----------------------

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:


Line 39:
Line 40:
Line 41: Label1.Text = WebUserControl1.FirstName
Line 42: Label2.Text = WebUserControl1.LastName
Line 43:


Source File: c:\inetpub\wwwroot\WebApplication3
\WebForm1.aspx.vb Line: 41

Stack Trace:


[NullReferenceException: Object reference not set to an
instance of an object.]
WebApplication3.WebForm1.Button1_Click(Object sender,
EventArgs e) in c:\inetpub\wwwroot\WebApplication3
\WebForm1.aspx.vb:41
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEv
entHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()




----------------------------------------------------------
----------------------
Version Information: Microsoft .NET Framework
Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Here is the code for the aspx.

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="WebApplication3.WebForm1"%>
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE"
content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<P>
<uc1:WebUserControl1
id="WebUserControl11"
runat="server"></uc1:WebUserControl1></P>
<P>
<asp:Button id="Button1"
runat="server" Text="Button"></asp:Button></P>
<P>First Name:
<asp:Label id="Label1"
runat="server">Label</asp:Label></P>
<P>Last Name:
<asp:Label id="Label2"
runat="server">Label</asp:Label></P>
</form>
</body>
</HTML>
Public Class WebForm1
Inherits System.Web.UI.Page

#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 Button1 As
System.Web.UI.WebControls.Button
Protected WithEvents Label1 As
System.Web.UI.WebControls.Label
Protected WithEvents Label2 As
System.Web.UI.WebControls.Label

'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

Public WithEvents WebUserControl1 As
WebApplication3.WebUserControl1

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click

'Dim cont As New WebUserControl1



Label1.Text = WebUserControl1.FirstName
Label2.Text = WebUserControl1.LastName

End Sub
End Class

Here is the code for the ascx.

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WebUserControl1.ascx.vb"
Inherits="WebApplication3.WebUserControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie
5" %>
<P>First Name:
<asp:TextBox id="TextBox1"
runat="server"></asp:TextBox></P>
<P>Last Name:
<asp:TextBox id="TextBox2"
runat="server"></asp:TextBox></P>

Public MustInherit 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 TextBox1 As
System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As
System.Web.UI.WebControls.TextBox

'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

Public ReadOnly Property FirstName() As String
Get
Return Me.TextBox1.Text
End Get
End Property

Public ReadOnly Property LastName() As String
Get
Return Me.TextBox2.Text
End Get
End Property

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
End Sub

End Class
 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      10-23-2003
Hi Christopher,

>>>>Line 41: Label1.Text = WebUserControl1.FirstName

Either Label1 or WebUserControl1 is null at this point, have you tried using
a debugger to know which one is evaluating to null.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

and not by private mail.
"Christopher Young" <(E-Mail Removed)> wrote in message
news:027801c39743$b6d17850$(E-Mail Removed)...
> Here is my error. I have tried something similar in a
> larger application I am working on and got similar
> results. Thanks for any help in advance.
>
> Server Error in '/WebApplication3' Application.
> ----------------------------------------------------------
> ----------------------
>
> 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:
>
>
> Line 39:
> Line 40:
> Line 41: Label1.Text = WebUserControl1.FirstName
> Line 42: Label2.Text = WebUserControl1.LastName
> Line 43:
>
>
> Source File: c:\inetpub\wwwroot\WebApplication3
> \WebForm1.aspx.vb Line: 41
>
> Stack Trace:
>
>
> [NullReferenceException: Object reference not set to an
> instance of an object.]
> WebApplication3.WebForm1.Button1_Click(Object sender,
> EventArgs e) in c:\inetpub\wwwroot\WebApplication3
> \WebForm1.aspx.vb:41
> System.Web.UI.WebControls.Button.OnClick(EventArgs e)
>
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEv
> entHandler.RaisePostBackEvent(String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent
> (IPostBackEventHandler sourceControl, String
> eventArgument)
> System.Web.UI.Page.RaisePostBackEvent
> (NameValueCollection postData)
> System.Web.UI.Page.ProcessRequestMain()
>
>
>
>
> ----------------------------------------------------------
> ----------------------
> Version Information: Microsoft .NET Framework
> Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
>
> Here is the code for the aspx.
>
> <%@ Page Language="vb" AutoEventWireup="false"
> Codebehind="WebForm1.aspx.vb"
> Inherits="WebApplication3.WebForm1"%>
> <%@ Register TagPrefix="uc1" TagName="WebUserControl1"
> Src="WebUserControl1.ascx" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
> Transitional//EN">
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" content="Microsoft
> Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE"
> content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript"
> content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body>
> <form id="Form1" method="post"
> runat="server">
> <P>
> <uc1:WebUserControl1
> id="WebUserControl11"
> runat="server"></uc1:WebUserControl1></P>
> <P>
> <asp:Button id="Button1"
> runat="server" Text="Button"></asp:Button></P>
> <P>First Name:
> <asp:Label id="Label1"
> runat="server">Label</asp:Label></P>
> <P>Last Name:
> <asp:Label id="Label2"
> runat="server">Label</asp:Label></P>
> </form>
> </body>
> </HTML>
> Public Class WebForm1
> Inherits System.Web.UI.Page
>
> #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 Button1 As
> System.Web.UI.WebControls.Button
> Protected WithEvents Label1 As
> System.Web.UI.WebControls.Label
> Protected WithEvents Label2 As
> System.Web.UI.WebControls.Label
>
> '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
>
> Public WithEvents WebUserControl1 As
> WebApplication3.WebUserControl1
>
> Private Sub Page_Load(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles MyBase.Load
>
> End Sub
>
> Private Sub Button1_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> Button1.Click
>
> 'Dim cont As New WebUserControl1
>
>
>
> Label1.Text = WebUserControl1.FirstName
> Label2.Text = WebUserControl1.LastName
>
> End Sub
> End Class
>
> Here is the code for the ascx.
>
> <%@ Control Language="vb" AutoEventWireup="false"
> Codebehind="WebUserControl1.ascx.vb"
> Inherits="WebApplication3.WebUserControl1"
> TargetSchema="http://schemas.microsoft.com/intellisense/ie
> 5" %>
> <P>First Name:
> <asp:TextBox id="TextBox1"
> runat="server"></asp:TextBox></P>
> <P>Last Name:
> <asp:TextBox id="TextBox2"
> runat="server"></asp:TextBox></P>
>
> Public MustInherit 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 TextBox1 As
> System.Web.UI.WebControls.TextBox
> Protected WithEvents TextBox2 As
> System.Web.UI.WebControls.TextBox
>
> '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
>
> Public ReadOnly Property FirstName() As String
> Get
> Return Me.TextBox1.Text
> End Get
> End Property
>
> Public ReadOnly Property LastName() As String
> Get
> Return Me.TextBox2.Text
> End Get
> End Property
>
> 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
> End Sub
>
> End Class



 
Reply With Quote
 
 
 
 
Christopher Young
Guest
Posts: n/a
 
      10-23-2003
It is the WebUserControl1 that is throwing the exception.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      10-23-2003
Ok, if WebUserControl1 evaluates to null chances are the parser isn't doing
its magic. Quickly looking at your code again I noticied that:

>>> Public WithEvents WebUserControl1 As WebApplication3.WebUserControl1


>>> <uc1:WebUserControl1 id="WebUserControl11"> runat="server">


The value for the ID attribute of the <uc1:WebUserControl1> tag is not
matching the name of your member variable, you need both to match for the
parser to do its magic, so try changing the previous line to:

<uc1:WebUserControl1 id="WebUserControl1"> runat="server">

and it should working,

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

and not by private mail.
"Christopher Young" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It is the WebUserControl1 that is throwing the exception.
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
searching what groups a user belong from AD but errorThe Kerberos subsystem encountered an error. A service for user protocol request was made rote ASP .Net Security 13 01-04-2008 06:20 AM
trying to spawn a process (say an exe file) with different user crendentials than that of the current user but getting 1314 error ranju C++ 1 05-18-2007 02:35 AM
Error:Login failed for user ''. The user is not associated with a trusted SQL Server connection. CFTK ASP .Net 5 01-09-2007 10:51 AM
problems in vc++:Applying setting user breakpoint, unhandled exception ,linking error,runtime error manish C++ 1 04-02-2004 12:33 PM
How do you figure out the LDAP://? ("Error authenticating. Error authenticating user. The specified domain either does not exist or could not be contacted") mrwoopey ASP .Net 3 06-30-2003 10:11 PM



Advertisments