Hi jellybeannn, hope you're fine...
At code-behind inn your program (CreateUserWizard1_CreateUser handler), you put this line of code...
Roles.AddUserToRole((sender as CreateUserWizard).UserName,"Customer");
Up to this point program is okay, because it get the element as object from sender and cast it to use as CreateUserWizard type object.
The problem starts from next statement which is something like...
ProfileCommon p = ......
I suggest to take the element you extracted from sender into a CreateUserWizard type variable... and then use this variable to refer actual element... lets see the approach...
replace your handler function with one given below:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
CreateUserWizard cuw = (CreateUserWizard) sender;
Roles.AddUserToRole(cuw.UserName,"Customer");
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(cuw.UserName, true);
p.Name = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Name")).Text;
p.Surname = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Surname")).Text;
p.Save();
}
or you can try another approach by extracting CreateUserWizard element from containing element (not by sender)... try this code:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
CreateUserWizard cuw = (CreateUserWizard) LoginView1.FindControl("CreateUserWizard1");
Roles.AddUserToRole(cuw.UserName,"Customer");
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(cuw.UserName, true);
p.Name = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Name")).Text;
p.Surname = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Surname")).Text;
p.Save();
}
I hope you got your answer...Good Luck!