Setting Member properties from ASP.NET user control using CreateUserWizard control
OK, I've created a macro with an ASP.NET user control which creates a user and adds that user to a group (which is passed as a macro parameter).
The thing is, I have discovered that the registration form needs to have additional fields. I've added several new member properties in Umbraco, but I can't work out how to access them from the user control.
As ever, I'd appreciate any help with this.
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName) Roles.AddUserToRole(CreateUserWizard1.UserName, MemberGroup) Response.Redirect("/")
I needed to use the Umbraco Member object instead of the ASP.NET MembershipUser object.
If anybody else comes looking for this information,in order to use the Umbraco API in a Visual Studio project, you have to copy businesslogic.dll, cms.dll, and umbraco.dll from the Umbraco bin directory to the bin directory of the project with your user control with the CreateUserWizard control in it, and add references to those files in your Visual Studio project.
Here's what I did -
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
' The following four lines create TextBox objects for the TextBoxes in the customized CreateUserWizard ContentTemplate -
Dim TitleTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Title"), TextBox) Dim FirstNameTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"), TextBox) Dim LastNameTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"), TextBox) Dim JobTitleTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("JobTitle"), TextBox)
' Gets the member details based on the UserName Dim registeredMember As Member = Member.GetMemberFromLoginName(CreateUserWizard1.UserName)
' Use the getProperty method to set the custom member properties.
Setting Member properties from ASP.NET user control using CreateUserWizard control
OK, I've created a macro with an ASP.NET user control which creates a user and adds that user to a group (which is passed as a macro parameter).
The thing is, I have discovered that the registration form needs to have additional fields. I've added several new member properties in Umbraco, but I can't work out how to access them from the user control.
As ever, I'd appreciate any help with this.
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
Roles.AddUserToRole(CreateUserWizard1.UserName, MemberGroup)
Response.Redirect("/")
End Sub
End Class
Never mind, I figured it out myself.
I needed to use the Umbraco Member object instead of the ASP.NET MembershipUser object.
If anybody else comes looking for this information,in order to use the Umbraco API in a Visual Studio project, you have to copy businesslogic.dll, cms.dll, and umbraco.dll from the Umbraco bin directory to the bin directory of the project with your user control with the CreateUserWizard control in it, and add references to those files in your Visual Studio project.
Here's what I did -
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
' The following four lines create TextBox objects for the TextBoxes in the customized CreateUserWizard ContentTemplate -
Dim TitleTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Title"), TextBox)
Dim FirstNameTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"), TextBox)
Dim LastNameTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"), TextBox)
Dim JobTitleTextBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("JobTitle"), TextBox)
' Gets the member details based on the UserName
Dim registeredMember As Member = Member.GetMemberFromLoginName(CreateUserWizard1.UserName)
' Use the getProperty method to set the custom member properties.
registeredMember.getProperty("firstName").Value = FirstNameTextBox.Text
registeredMember.getProperty("lastName").Value = LastNameTextBox.Text
registeredMember.getProperty("jobTitle").Value = JobTitleTextBox.Text
registeredMember.Save()
End Sub
Hi,
Thanks for posting your findings!
If you're interested in an alternate method, check out this blog post: http://www.aaron-powell.com/umbraco-members-profiles
-Tom
is working on a reply...