Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   User control property reference gives null error (http://www.velocityreviews.com/forums/t773821-user-control-property-reference-gives-null-error.html)

Harry Higbie 07-15-2004 05:39 PM

User control property reference gives null error
 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
error refers to line 34.

This is a very simple example, and there are no syntax flags when the code is built. Is this enough info? What should I look at to fix this?

This is happening in 2003 version of Visual Studio .NET when page and user control are both built there.

Source Error:


Line 32:
Line 33: Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Line 34: Response.Write(uc1.mything)
Line 35: End Sub
Line 36: End Class



Works OK, built in pre-2003 VS .NET:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents btnGet As System.Web.UI.WebControls.Button
Protected WithEvents simplecontrol1 As SimpleControl

#Region " Web Form Designer Generated Code "

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

End Sub

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

Private Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click
Response.Write(SimpleControl1.TextValue)
End Sub
End Class

Does not work (built in VS .NET 2003):
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents lblResult As System.Web.UI.WebControls.Label
Protected WithEvents uc As UserName
Protected WithEvents uc1 As Userx

#Region " Web Form Designer Generated Code "

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

End Sub


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

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Response.Write(uc1.mything)
End Sub
End Class

This is the user control object VB code:
Public Class Userx
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 Label1 As System.Web.UI.WebControls.Label
Protected WithEvents txtName1 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

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
Public Property mything() As String
Get
Return txtName1.Text
End Get
Set(ByVal Value As String)
txtName1.Text = Value
End Set
End Property

End Class

Thanks, in advance, Harry Higbie


All times are GMT. The time now is 08:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.