c# - CreateUserWizard 中的 ActiveStepChanged

标签 c# asp.net

我正在阅读 membership tutorial from ASP.NET

我目前正处于标题为:

Customizing the CreateUserWizard’s Interface to Prompt for the New User’s Home Town, Homepage, and Signature

应该发生的是,我向我的 CreateUserWizard 添加了一个自定义“步骤”,但是当我运行这个自定义步骤并点击“继续”时,这些值不会插入到我的数据库中,如果出现问题,那么它应该将“NULL”插入数据库(如教程所述,“如果用户在第 2 步期间关闭注册,它将自动插入 NULL”,但即使这样也不会发生。

我的数据库有 1 个关系,从 UserProfiles_Id 到 Aspnet_Users_UserId:

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)

关于c# - CreateUserWizard 中的 ActiveStepChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9093393/

相关文章:

c# - 为什么我不应该使类可序列化?

asp.net - 如果身份验证 cookie 是由服务器通过 SSL 发布的,它会被盗吗?

asp.net - asp.net 文本框的默认值 -> TextMode = 密码

C#密码加密

c# - 如何注销 session MVC Razor visual studio

c# - 对 ListView 中的条目进行排序

c# - 如何在C#中调整按钮上的图片大小?

javascript - 如何将 JavaScript (Node.js) 数组转换为 C# 字符串数组?

c# - 有没有办法在 ASP.NET 中将身份验证从一个 Web 应用程序持久保存到另一个嵌套的 Web 应用程序?

c# - 没有参数的 SQL 注入(inject)攻击的任何风险,但强制用户输入仅限于正则表达式 [a-zA-Z][a-zA-Z0-9]*?