Assigning Profile Properties When A User Registers With CreateUserWizard

N

Nathan Sokalski

I am working with ASP.NET Membership, and want to assign values to the
Profile properties when a user registers using the CreateUserWizard. I have
the LoginCreatedUser property of my CreateUserWizard set to True, but when I
use the HttpContext.Current.Profile.SetPropertyValue method in the
CreatedUser event, it tells me I cannot set this for anonymous users. Where
and how should I set any Profile properties I want to set during
registration? Thanks.
 
M

miher

Hi,
I think You have to wait with setting Profile values until the user gets
created, and she gets logged in.
A suitable event can be the ContinueButtonClick event of the wizard, what is
fired if the Continue button is clicked on the second(finish) page of a
default wizard.
In the handler of this event You should be able to set Profile values.

Hope You find this useful.
-Zsolt
 
P

Paul Shapiro

I tried setting profile properties in the CreateUserWizard.CreatedUser
event, but I got the same error about an anonymous user. I thought from the
documentation that both the user and the profile would already exist:
"Use the CreatedUser event to set Web site values, such as
personalization values, before the user is logged on to the site for the
first time."

Maybe the user exists, but it doesn't seem the Profile exists yet. I moved
the code to a page event, where it now checks to see if the Profile has been
initialized. I would also like to find a more appropriate event for initial
Profile setup.
 
N

Nathan Sokalski

I finally found an answer, take a look at:

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

I'm not sure where the class ProfileCommon comes from, because I have been
unable to get Intellisense to list it, but when I use ProfileBase instead
everything works fine. Here is a copy of my code just so you can see what I
did:

Private Sub cuwRegister_CreatedUser(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cuwRegister.CreatedUser
Dim tempprofile As ProfileBase =
ProfileBase.Create(Me.cuwRegister.UserName, True)
Dim bday As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtBirthday"),
TextBox).Text
Dim loc As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("ddlLangOfChoice"),
DropDownList).SelectedValue
Dim site As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtWebsite"),
TextBox).Text

If Not String.IsNullOrEmpty(bday) Then
tempprofile.SetPropertyValue("Birthday", CDate(bday))
If Not String.IsNullOrEmpty(loc) Then
tempprofile.SetPropertyValue("LanguageOfChoice", loc)
If Not String.IsNullOrEmpty(site) Then
tempprofile.SetPropertyValue("PersonalWebsite", site)
tempprofile.Save()
End Sub

Hopefully this will save you some of the frustration that I had, good luck!
 
P

Paul Shapiro

Thanks very much! That's a big help.

Nathan Sokalski said:
I finally found an answer, take a look at:

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

I'm not sure where the class ProfileCommon comes from, because I have been
unable to get Intellisense to list it, but when I use ProfileBase instead
everything works fine. Here is a copy of my code just so you can see what
I did:

Private Sub cuwRegister_CreatedUser(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cuwRegister.CreatedUser
Dim tempprofile As ProfileBase =
ProfileBase.Create(Me.cuwRegister.UserName, True)
Dim bday As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtBirthday"),
TextBox).Text
Dim loc As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("ddlLangOfChoice"),
DropDownList).SelectedValue
Dim site As String =
CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtWebsite"),
TextBox).Text

If Not String.IsNullOrEmpty(bday) Then
tempprofile.SetPropertyValue("Birthday", CDate(bday))
If Not String.IsNullOrEmpty(loc) Then
tempprofile.SetPropertyValue("LanguageOfChoice", loc)
If Not String.IsNullOrEmpty(site) Then
tempprofile.SetPropertyValue("PersonalWebsite", site)
tempprofile.Save()
End Sub

Hopefully this will save you some of the frustration that I had, good
luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top