Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 15, 2012 @ 15:35
    Anthony Candaele
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 13:15
    Anthony Candaele
    0

    anyone a suggestion?

    Thanks for your help,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 16, 2012 @ 13:31
    Jeroen Breuer
    2

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 14:23
    Tom Fulton
    101

    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:

                if (!Page.IsPostBack)
                {
                    MemberProfile mp = ((MemberProfile)HttpContext.Current.Profile);
                    MembershipUser user = Membership.GetUser(mp.UserName);
                    Username.Text = mp.UserName;
                    Email.Text = user.Email;
                    FirstName.Text = mp.FirstName;
                    LastName.Text = mp.LastName;
                }

    And on your button click:

                if (Page.IsValid)
                {
                    MemberProfile mp = ((MemberProfile)HttpContext.Current.Profile);
                    mp.SetPropertyValue("mFirstName", FirstName.Text);
                    mp.SetPropertyValue("mLastName", LastName.Text);

                    mp.Save();
                    HttpContext.Current.Profile.Save();
                    Membership.UpdateUser(Membership.GetUser(HttpContext.Current.Profile.UserName));
                }

    HTH,
    Tom

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 18:47
    Anthony Candaele
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 19, 2012 @ 10:17
    Anthony Candaele
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 19, 2012 @ 13:32
    Tom Fulton
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 23, 2012 @ 15:48
    Anthony Candaele
    0

    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

     

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 23, 2012 @ 16:13
    Anthony Candaele
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 23, 2012 @ 17:46
    Tom Fulton
    1

    Hi Anthony,

    Have you tried this instead:

    ddlCountry.SelectedValue = mp.Country;

    -Tom

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 23, 2012 @ 18:00
    Anthony Candaele
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 23, 2012 @ 22:41
    Tom Fulton
    1

    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?

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 24, 2012 @ 17:45
    Anthony Candaele
    0

    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'

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 25, 2012 @ 05:49
    Tom Fulton
    1

    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; 

    I think one of those may work.

    -Tom

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 25, 2012 @ 09:19
    Anthony Candaele
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft