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
Hi,I am trying to generate http request strings beyond the header/value pairs that seem tobe support...
By keitht
How do I go about reading a setting from another applications .config file in .Net 2.0Just to be cle...
By kukulcan
I have a C# application where i've set .keypress of both a textbox and combobox to the same key...
By anonymous
Howdy all,I building a simulation tool, and am having trouble with Keypress events. I am using a for...
By codefund_com
Hallo,I am trying to capture the Keyeevnt F5 in the application.However the event does'nt gets captu...
By swingme, 1 Comments
Hi,In my application, how could i find the active form ( current form on screen) from some where els...
By codefund_com, 2 Comments
Hi, I am writing an application that has to be run via a web browser and it also must run using the ...
By anonymous, 7 Comments
Is there a way to make the right mouse button actually select an item in a listbox as well as popup ...
By anonymous, 2 Comments
Hi all,I'm playing sound files(ringtone alert) using VB.net.It is working fine on my client local PC...
By mpgrewal_net, 1 Comments
Can you show your CreateUserProfile code?
thejd | Sun, 06 Jan 2008 06:29:00 GMT |
It's there...in my original post. I don't think the CreateUserProfile piece is the problem though. I put text boxes on the form outside the loginview and the create user wizard (to eliminate nesting issues). The text boxes corresponded to the values passed to the CreateUserProfile piece. I tried running the form with these non-nested controls and everything worked. So it must be something wrong with the FindControl lines in the CreateUserWizard_CreatedUser sub.
mdcragg | Sun, 06 Jan 2008 06:30:00 GMT |
Okay...I fixed my own problem. I have to reference the controls in the wizard like this:
Dim FirstNameAs TextBoxFirstName =
CType(CWZ.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName"), TextBox)mdcragg | Sun, 06 Jan 2008 06:31:00 GMT |