Question

I am developing a site for our company that will enable users from other companies to order directly from our company. I have already assign user roles and programatically assigned them based upon a few selections during registration. I have added a page that uses the CreateUserWizard form, with an added step to collect some more information from the customer (specifically the company name so we know which parts to allow them to order). The problem is that once someone fills out the first registration process and clicks "Create User", the user is created there and directs them to the next step where I collect the company information. If the user aborts the process, the user account is still created, and they are not assigned to a usergroup. The last page (step) of the CreateUserWizard has a finish button where it assigns them to the user group based upon a few selections from the second step. How can I keep the user from being added until the registration process is actually completed? Here is the code I have so far behind the scenes.

protected void RegisterUser_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (companyddl.SelectedValue == ""){
         errorlbl.Text = "Please Select A Company You Will Be Ordering Parts From.";

         MembershipCreateStatus createStatus = new MembershipCreateStatus();
         MembershipUser newUser = System.Web.Security.Membership.CreateUser(RegisterUser.UserName, RegisterUser.Password, RegisterUser.Email,
                                  RegisterUser.Question, RegisterUser.Answer, true, out createStatus);

         if (companyddl.SelectedValue == "SF")
             Roles.AddUserToRole(RegisterUser.UserName, "user_sf");
         if (companyddl.SelectedValue == "TL")
             Roles.AddUserToRole(RegisterUser.UserName, "user_tl");
         if (companyddl.SelectedValue == "" && companytxt.Text != "OurCompany")
             Roles.AddUserToRole(RegisterUser.UserName, "user");
         if ((companytxt.Text == "OurCompany" || companytxt.Text == "OurCompany, Inc.") && companyddl.SelectedValue == "")
             Roles.AddUserToRole(RegisterUser.UserName, "manager");
    }
}
Was it helpful?

Solution 2

I found a solution. I just changed the registration steps in the wizard so it will first ask for the company and other info then the username, password etc.

OTHER TIPS

You should save to temporary somewhere (Session, temporary table in db, or other) then batch all input in the last step/

I'm not sure what your code is doing... it appears that it's performing validation, but then continues to create the user. Shouldn't it be:

protected void RegisterUser_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (companyddl.SelectedValue == ""){
         errorlbl.Text = "Please Select A Company You Will Be Ordering Parts From.";
         return;
    }

    MembershipCreateStatus createStatus = new MembershipCreateStatus();
    MembershipUser newUser = System.Web.Security.Membership.CreateUser(RegisterUser.UserName, RegisterUser.Password, RegisterUser.Email, RegisterUser.Question, RegisterUser.Answer, true, out createStatus);

    if (companyddl.SelectedValue == "SF")
        Roles.AddUserToRole(RegisterUser.UserName, "user_sf");
    if (companyddl.SelectedValue == "TL")
        Roles.AddUserToRole(RegisterUser.UserName, "user_tl");
    if (companyddl.SelectedValue == "" && companytxt.Text != "OurCompany")
        Roles.AddUserToRole(RegisterUser.UserName, "user");
    if ((companytxt.Text == "OurCompany" || companytxt.Text == "OurCompany, Inc.") && companyddl.SelectedValue == "")
        Roles.AddUserToRole(RegisterUser.UserName, "manager");

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top