Question

I Have the following code which fires OnCreatedUser and doesn't throw any errors. Profile.Title is getting set to the correct value when inspected after the assignment.

public void CreateUserForm_CreatedUser(object sender, EventArgs e)
{
    var ddlTitle = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Title");
    Profile.Title = ddlTitle.SelectedValue;
    Profile.Save();
}

However, when I test Profile.Title on subsequent pages (the user is definitely logged in) it is == "";

I'm guessing that this is the users old anonymous profile, not the new profile associated with their newly registered user account.

I've tried adding a Profile_MigrateAnonymous method (as suggested here) to my Global.asax but this code doesn't get hit.

How do I save title to the new users account profile?

UPDATE
Here's the code

public void CreateUserForm_CreatedUser(object sender, EventArgs e)
{
     var ddlTitle = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Title");
     var emailTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
     UserProfile profile = (UserProfile)ProfileBase.Create(emailTextBox.Text.Trim());
     profile.Title = ddlTitle.SelectedValue;
     profile.Save();
}
Was it helpful?

Solution

I think you're correct that the user is still anonymous while that method is called. I'm not familiar with Profile, but I think you need to look the profile up by username instead of relying on the current profile.

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