我正在阅读membership tutorial from ASP.NET
我目前处于标题为:
自定义CreateUserWizard的界面以提示新的
用户的家乡,主页和签名
应该发生的是,我向我的CreateUserWizard添加了一个自定义的“步骤”,但是当我运行此自定义步骤并单击“继续”时,这些值未插入到我的数据库中,如果出现问题,则说明该错误应该在数据库中插入“ NULL”(如本教程所述,“如果用户在步骤2中关闭了注册,它将自动插入NULL”,但即使如此也不会发生。
我的数据库与UserProfiles_Id to Aspnet_Users_UserId:
有1个关联
FK_UserProfiles_aspnet_Users
我已经完成了服务时间的步骤,但仍然找不到问题。
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();
}
}
}
最佳答案
尝试换线
if (NewUserWizard.ActiveStep.Title == "Complete")
至
if (NewUserWizard.ActiveStep == this.CompleteWizardStep1)