I am reading a membership tutorial from ASP.NET
I am currently at the step titled:
Customizing the CreateUserWizard’s Interface to Prompt for the New User’s Home Town, Homepage, and Signature
What is supposed to happen is that I add a custom "step" to my CreateUserWizard, but when I run through this custom Step and hit "Continue", the values are NOT inserted into my Database, and if something is going wrong, then it should insert "NULL" into the database (as the tutorial tells, "if the user closes the registration during step 2, it will automatically insert NULL", but even that doesn't happen.
My database have 1 relation from UserProfiles_Id to Aspnet_Users_UserId:
FK_UserProfiles_aspnet_Users
I have gone through the steps in the tutorial serval times and I am still unable to find the problem.
Aspx.:
<asp:CreateUserWizard ID="NewUserWizard" runat="server" ContinueDestinationPageUrl="~/bruger/info.aspx">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep" runat="server">
</asp:CreateUserWizardStep>
<asp:WizardStep ID="UserSettings" runat="server" StepType="Step" Title="Dine Informationer">
<p>Navn:<br />
<asp:TextBox ID="Name" runat="server" TextMode="SingleLine" />
</p>
<p>Adresse:<br />
<asp:TextBox ID="Adress" Columns="40" runat="server" TextMode="SingleLine" />
</p>
<p>Postnummer:<br />
<asp:TextBox ID="ZipCode" Columns="20" Rows="5" runat="server" TextMode="SingleLine" />
</p>
<p>By:<br />
<asp:TextBox ID="City" Columns="40" runat="server" TextMode="SingleLine" />
</p>
</asp:WizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" >
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
Aspx.cs:
protected void NewUserWizard_ActiveStepChanged(object sender, EventArgs e)
{
// Have we JUST reached the Complete step?
if (NewUserWizard.ActiveStep.Title == "Complete")
{
WizardStep UserSettings = NewUserWizard.FindControl("UserSettings") as
WizardStep;
// Programmatically reference the TextBox controls
TextBox Name = UserSettings.FindControl("Name") as TextBox;
TextBox Adress = UserSettings.FindControl("Adress") as TextBox;
TextBox ZipCode = UserSettings.FindControl("ZipCode") as TextBox;
TextBox City = UserSettings.FindControl("City") as TextBox;
// Update the UserProfiles record for this user
// Get the UserId of the just-added user
MembershipUser newUser = Membership.GetUser(NewUserWizard.UserName);
Guid newUserId = (Guid)newUser.ProviderUserKey;
// Insert a new record into UserProfiles
string connectionString =
ConfigurationManager.ConnectionStrings["LLCateringConnectionString"].ConnectionString;
string updateSql = @"UPDATE UserProfiles SET Name = @Name, Adress = @Adress, ZipCode = @ZipCode, City = @City
WHERE UserId = @UserId";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(updateSql, myConnection);
myCommand.Parameters.AddWithValue("@Name", Name.Text.Trim());
myCommand.Parameters.AddWithValue("@Adress", Adress.Text.Trim());
myCommand.Parameters.AddWithValue("@ZipCode", ZipCode.Text.Trim());
myCommand.Parameters.AddWithValue("@City", City.Text.Trim());
myCommand.Parameters.AddWithValue("@UserId", newUserId);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}
Try to change the line
if (NewUserWizard.ActiveStep.Title == "Complete")
to
if (NewUserWizard.ActiveStep == this.CompleteWizardStep1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With