Now I looking to create functionality to enable members to edit their profile data. I guess I should create another user control for this and read out the member profile data in an editing form.
Has anyone of you done this before or can anybody point me to useful information to realise this scenario?
I've done this before. You just create a usercontrol with all the fields you want to edit and in the back of you usercontrol you update the fields with the member API (I still find that the easiest way). For stuff like a date it could be easy to use a datatype on the frontend of your website (yes that's also possible). Have a look at some examples here on how to use custom datatypes: http://our.umbraco.org/forum/developers/extending-umbraco/27640-Adding-data-type-to-custom-section-in-CMS?p=0#comment103433.
+1 to what Jeroen said, just create a new usercontrol for this and add all the controls you need. I think you are using a custom MemberProfile class to access your member data, so you can easily populate and save the data with this.
Currently working on the EditProfile.ascx user control and everything is working fine. Thanks for your demo code. Just a few questions, to fully grasp the code:
mp.Save();
Why, after mp.Save() are the next two lines of code necessary?:
To be honest I don't know the specifics, but the reason I added those lines is because I was having problems with the user's "session" updating. For instance, if they changed their first name, it would still show their old first name in the "Hello, xxxx" box until they logged out and back in. After adding these lines (maybe one isn't necessary) it fixed the issue :)
For the member profile page, the selected country also needs to be editable. The country member property is of datatype uComponents Country Picker:
In order to enable the member to edit his country data, I should be able to access from within my EditProfile.ascx usercontrol the selected country that is stored as the selected item in country memberproperty (of type uComponents Country Picker).
I use this code to access the selected country from the member profile and set it as selected listitem on the dropdownlist control in my EditProfile.ascx usercontrol:
Tried this, but then the selected value in the dropdownlist on the EditProfile form is the value of the language culture of the browser, in my case 'Belgium'. While the test member had 'Senegal' for country.
Hmm, I don't see why that would happen. You are setting the SelectedValue after you call the Fill function right? Have you checked to ensure mp.Country is correct?
Perhaps the dropdownlist is using the country's code (MX) rather than it's name (Mexico) for the value? Otherwise that could should work fine, the only reason I can think it wouldn't is if "Mexico" didn't exist in the list. So one way around that if you don't want to adjust the dropdownlist would be something like this (untested):
ddlCountry.Items.FindByText(mp.Country).Selected = true; or ddlCountry.SelectedValue = ddlCountry.Items.FindByText(mp.Country).Value;
Enable members to edit their profile data
Hi,
I'm busy extending Umbraco with member registration functionality (you can read all about it in this forum thread). I was able to do this with the good help of Umbraco community members like Tom Fulton and Mike Taylor (Mike wrote an excellent blog post on this subject: "Authenticating new members before activating them").
Now I looking to create functionality to enable members to edit their profile data. I guess I should create another user control for this and read out the member profile data in an editing form.
Has anyone of you done this before or can anybody point me to useful information to realise this scenario?
Thanks for your help,
Anthony
anyone a suggestion?
Thanks for your help,
Anthony
Hello,
I've done this before. You just create a usercontrol with all the fields you want to edit and in the back of you usercontrol you update the fields with the member API (I still find that the easiest way). For stuff like a date it could be easy to use a datatype on the frontend of your website (yes that's also possible). Have a look at some examples here on how to use custom datatypes: http://our.umbraco.org/forum/developers/extending-umbraco/27640-Adding-data-type-to-custom-section-in-CMS?p=0#comment103433.
Jeroen
Hi Anthony,
+1 to what Jeroen said, just create a new usercontrol for this and add all the controls you need. I think you are using a custom MemberProfile class to access your member data, so you can easily populate and save the data with this.
Ex, on Page_Load:
And on your button click:
HTH,
Tom
Hi Jeroen, hi Tom,
Thanks for your suggestions. You guys rock! I'll give it a try and let you know how it went.
greetings,
Anthony
Hi Tom,
Currently working on the EditProfile.ascx user control and everything is working fine. Thanks for your demo code. Just a few questions, to fully grasp the code:
mp.Save();
Why, after mp.Save() are the next two lines of code necessary?:
HttpContext.Current.Profile.Save();
Membership.UpdateUser(Membership.GetUser(HttpContext.Current.Profile.UserName));
Thanks for enlightening me :)
Anthony
Hi Anthony,
To be honest I don't know the specifics, but the reason I added those lines is because I was having problems with the user's "session" updating. For instance, if they changed their first name, it would still show their old first name in the "Hello, xxxx" box until they logged out and back in. After adding these lines (maybe one isn't necessary) it fixed the issue :)
-Tom
Hi,
For the member profile page, the selected country also needs to be editable. The country member property is of datatype uComponents Country Picker:
In order to enable the member to edit his country data, I should be able to access from within my EditProfile.ascx usercontrol the selected country that is stored as the selected item in country memberproperty (of type uComponents Country Picker).
How can this be done?
Thanks for your help,
Anthony
I'm almost there (but not quiet :)
I use this code to access the selected country from the member profile and set it as selected listitem on the dropdownlist control in my EditProfile.ascx usercontrol:
DropDownList ddlCountry = (DropDownList)FindControl("ddlCountry");
Utilities.FillWithISOCountries(ddlCountry);
ddlCountry.SelectedItem.Text = mp.Country;
the problem however, is that in the dropdownlist the selected country from the memberprofile appears twice:
As you can see in the screenshot, the countrie from the memberprofile, Mexico, appears twice now in the dropdownlist on the EditProfile form.
How can I make the countrie from the memberprofile appear as selected listitem of the dropdownlist on the EditProfile form?
thanks for your help,
Anthony
Hi Anthony,
Have you tried this instead:
-Tom
Hi Tom,
Tried this, but then the selected value in the dropdownlist on the EditProfile form is the value of the language culture of the browser, in my case 'Belgium'. While the test member had 'Senegal' for country.
greetings,
Anthony
Hmm, I don't see why that would happen. You are setting the SelectedValue after you call the Fill function right? Have you checked to ensure mp.Country is correct?
Hi Tom,
Yes, I set the SelectedValue after calling the Fill function. If I debug the code (see screenshot)
then the value of mp.Country is 'Mexico' and the value of ddlCountry.SelectedValue is 'BE'
Perhaps the dropdownlist is using the country's code (MX) rather than it's name (Mexico) for the value? Otherwise that could should work fine, the only reason I can think it wouldn't is if "Mexico" didn't exist in the list. So one way around that if you don't want to adjust the dropdownlist would be something like this (untested):
I think one of those may work.
-Tom
Hi Tom,
I tried
ddlCountry.Items.FindByText(mp.Country).Selected = true;
But then I got the errormessage that I cannot have multiple selected items in a dropdownlist.
So before setting the selected value on the dropdownlist, I cleared the previous selection:
ddlCountry.ClearSelection();
and now it works.
This is the full solution:
DropDownList ddlCountry = (DropDownList)FindControl("ddlCountry");
Utilities.FillWithISOCountries(ddlCountry);
ddlCountry.ClearSelection();
ddlCountry.Items.FindByText(mp.Country).Selected = true;
greetings,
Anthony
is working on a reply...