I am getting a Null Reference error. I am trying to harvest data from a CreateUserWizard using the lines of code below. I am then trying to pass that data to a procedure which posts the information in a database.
When I try this with only the CWZ.UserName value, it works. When I add the other custom controls that I added to the CreateUserWizard it fails with the error shown further below.
The CreateUserWizard is nested in a LoginView which is in turn nested in a ContentPlaceHolder.
Any ideas anybody? Thanks in advance.
<<<<<<<<<<<<<<<<<<<<<my code>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub CreateUserWizard_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
Dim CWZ As CreateUserWizard
CWZ = CType(Me.LoginView1.FindControl("CreateUserWizard"), Wizard)
Dim FirstName As TextBox
FirstName = CType(CWZ.FindControl("txtFirstName"), TextBox)
Dim LastName As TextBox
LastName = CType(CWZ.FindControl("txtLastName"), TextBox)
Dim Country As TextBox
Country = CType(CWZ.FindControl("ddlCountry"), TextBox)
Dim PostalCode As TextBox
PostalCode = CType(CWZ.FindControl("txtPostalCode"), TextBox)
CreateUserProfile(CWZ.UserName, FirstName.Text, LastName.Text, Country.Text, PostalCode.Text)
End Sub
Private Sub CreateUserProfile(ByVal UserName As String, ByVal FirstName As String, ByVal LastName As String, ByVal Country As String, ByVal PostalCode As String)
'Private Sub CreateUserProfile(ByVal userName As String)
Dim conString As String = WebConfigurationManager.ConnectionStrings("UserProfiles").ConnectionString
Dim con As New SqlConnection(conString)
Dim cmd As New SqlCommand("INSERT profiles_BasicProperties (UserName,FirstName,LastName,Country,PostalCode) VALUES (...UserName,...FirstName,...LastName,...Country,...PostalCode)", con)
cmd.Parameters.AddWithValue("...UserName", UserName)
cmd.Parameters.AddWithValue("...FirstName", FirstName)
cmd.Parameters.AddWithValue("...LastName", LastName)
cmd.Parameters.AddWithValue("...Country", Country)
cmd.Parameters.AddWithValue("...PostalCode", PostalCode)
Using con
con.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
<<<<<<<<<<<<<<<<<<<<<<<<<<<the error that I get (Line 29 is highlighted as the source of the error)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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 27: PostalCode = CType(CWZ.FindControl("txtPostalCode"), TextBox)
Line 28:
Line 29: CreateUserProfile(CWZ.UserName, FirstName.Text, LastName.Text, Country.Text, PostalCode.Text)
Line 30: 'CreateUserProfile(CWZ.UserName)
Line 31: 'CreateUserWizard_SendingMail(CWZ.UserName, e)
Source File: C:\Users\mdcragg\Documents\site\PC_Dev\User_Create.aspx Line: 29
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP.user_create_aspx.CreateUserWizard_CreatedUser(Object sender, EventArgs e) in C:\Users\mdcragg\Documents\site\PC_Dev\User_Create.aspx:29
System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs e) +105
System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +341
System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453
System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.312