views:

1843

answers:

3

Hi all,

I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I am very happy with it, apart from one thing. I have an extra field in the "Users" table. I have an overridden method for CreateUser() that takes in the extra variable and puts it into the DB.

My issues is that I want to be able to have this called from the Create User Wizard control. I have customized the control to have a drop down to populate my extra field. I have used the following code to store that piece of info but I am at a loss of how I either use the profile or call my custom CreateUser Method:

 // Create an empty Profile for the newly created user     
 ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

 // Populate some Profile properties off of the create user wizard
 p.CurrentLevel = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);

 // Save profile - must be done since we explicitly created it
 p.Save();

Thank you for any and all help

Jon Hawkins

+1  A: 

This is not the answer but I found a work around, would still like to know if someone could answer the question directly...

public void UpdateCurrentLvl_OnDeactivate(object sender, EventArgs e)
{
    int level = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);
    MyMembershipUser myUser = (MyMembershipUser)Membership.GetUser(CreateUserWizard1.UserName);
    myUser.CurrentLVL = level;
    Membership.UpdateUser(myUser);
}

In my first CreateUserWizardStep if put the method above to fire on deactivate. As at this point it has inserted the user into the DB I can get the User out, cast to my MembershipUser class, set the variable and all the update method.

As I say this is a work around from the way I would liked to have solved it but it works.

Thanks

Jon
+2  A: 

I think your solution is the "easiest" you're going to get. You could create your own wizard and call the correct method, but that's a lot more work.

The only thing I could recommend is using the OnCreatedUser event instead.

reference: 4guysfromrolla

Greg
+1 - Handling a Deactivate event sounds like a REALLY hacky workaround. I'm not sure exactly what the event does as I'm not sure what class it is coming from, but canonically, that is a UI functionality, and you should be basing your post-processing on the behavior of the membership provider instead
Daniel Schaffer
A: 

This is also incredibly hacky, but in the past when I've had to do similar things, I've just crammed the extra value into an unused parameter, like the password reset question or answer. Though, I'm not entirely sure how you'd manage this using the wizard.

It's ugly, but as long as it is explicitly documented (to be safe, I'd comment on the method itself as well as anywhere you reference it) it will work fine.

It's also a lot less work than creating your own wizard.

Daniel Schaffer