I am new to ASP.NET and am building an application with several UserControls. My problems lies when I try and set/return values from the ascx to an aspx page, I get the error: System.NullReferenceException: Object reference not set to an instance of an object
An example of my code to set the properties is shown below. Code-behind page for my ascx is:
Public MustInherit Class Customer
Inherits System.Web.UI.UserControl
...
...
Public Property pForename() As String
Get
Return txtForename.Text.Trim.ToString
End Get
Set(ByVal Value As String)
txtForename.Text = Value
End Set
End Property
Public Property pSurname() As String
Get
Return txtSurname.Text.Trim.ToString
End Get
Set(ByVal Value As String)
txtSurname.Text = Value
End Set
End Property
...
...
End Class
And my code-behind page for the aspx page is:
Imports System.Web.UI.UserControl
Public Class Request
Inherits System.Web.UI.Page
Protected pCustomer As Customer
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pCustomer.pSurname = "Smith"
pCustomer.pForename = "John"
End Sub
End Class
I wondered if my ascx page had not yet been loaded? Any help would be greatly appreciated.
Many thanks
Alasdair
An example of my code to set the properties is shown below. Code-behind page for my ascx is:
Public MustInherit Class Customer
Inherits System.Web.UI.UserControl
...
...
Public Property pForename() As String
Get
Return txtForename.Text.Trim.ToString
End Get
Set(ByVal Value As String)
txtForename.Text = Value
End Set
End Property
Public Property pSurname() As String
Get
Return txtSurname.Text.Trim.ToString
End Get
Set(ByVal Value As String)
txtSurname.Text = Value
End Set
End Property
...
...
End Class
And my code-behind page for the aspx page is:
Imports System.Web.UI.UserControl
Public Class Request
Inherits System.Web.UI.Page
Protected pCustomer As Customer
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pCustomer.pSurname = "Smith"
pCustomer.pForename = "John"
End Sub
End Class
I wondered if my ascx page had not yet been loaded? Any help would be greatly appreciated.
Many thanks
Alasdair