More in this section

Forums / Developing with Sitefinity / ManageProfile control not persisting changed values

ManageProfile control not persisting changed values

8 posts, 0 answered
  1. Hardy
    Hardy avatar
    21 posts
    Registered:
    27 Sep 2012
    18 May 2009
    Link to this post
    Hi,

    I want to display a custom form for the users of the site to change their profile information. I'm using the ManageProfile control wrapped in a user control as outlined in this thread. While I can display the EditTemplate just fine and the controls are automatically populated on load, there seems to be no way to actually persist the values that the user changed. I'm using the code as in the other thread but no matter what I try nothing is written to the database.

    Here are the relevant sections of the code:

    .ascx:
    <telerik:ManageProfile runat="server" ID="manageProfile" Mode="Edit" UsernameIfNoNames="false"
        <EditTemplate> 
            <h3>Profil bearbeiten</h3> 
            <fieldset> 
                <ul> 
                    <li> 
                        <asp:Label ID="lblSalutation" runat="server" Text="Anrede" AssociatedControlID="Salutation" /> 
                        <asp:DropDownList runat="server" ID="salutation" DataSourceID="salutationDataSource" 
                            DataTextField="Text" DataValueField="Text" /> 
                        <vtt:SalutationsDataSource runat="server" ID="salutationDataSource" /> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblTitle" runat="server" Text="Titel" AssociatedControlID="Title" /> 
                        <asp:TextBox ID="Title" runat="server"></asp:TextBox> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblFirstName" runat="server" Text="Vorname" AssociatedControlID="FirstName" /> 
                        <asp:TextBox ID="FirstName" runat="server"></asp:TextBox> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblLastName" runat="server" Text="Nachname" AssociatedControlID="LastName" /> 
                        <asp:TextBox ID="LastName" runat="server"></asp:TextBox> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblProfession" runat="server" Text="Berufsbezeichnung" AssociatedControlID="Profession" /> 
                        <asp:TextBox ID="Profession" runat="server"></asp:TextBox> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblCountry" runat="server" Text="Land" AssociatedControlID="Country" /> 
                        <asp:DropDownList runat="server" ID="country" DataSourceID="countriesDataSource" 
                            DataTextField="Text" DataValueField="Value"
                        </asp:DropDownList> 
                        <vtt:CountriesDataSource runat="server" ID="countriesDataSource" /> 
                    </li> 
                    <li> 
                        <asp:Label ID="lblLanguage" runat="server" Text="Sprache" AssociatedControlID="Language" /> 
                        <asp:TextBox ID="Language" runat="server"></asp:TextBox> 
                    </li>                 
                </ul> 
            </fieldset> 
          </EditTemplate> 
    </telerik:ManageProfile> 
    <asp:Button runat="server" ID="cmdSaveUser" CommandName="Save" OnCommand="cmdSaveUser_Command" Text="Speichern" /> 

    .cs
    public partial class ManageUserProfile : System.Web.UI.UserControl 
        {         
            protected void Page_Load(object sender, EventArgs e) 
            { 
                if (!Page.IsPostBack) 
                {                 
                    manageProfile.Mode = Telerik.Security.WebControls.ManageProfile.Modes.Edit; 
                    BindForm(); 
                } 
            } 
     
            protected void cmdSaveUser_Command(object sender, CommandEventArgs e) 
            {             
                MembershipUser user = UserManager.Default.GetUser(); 
                manageProfile.SetProfileProperties(user.UserName); 
                UserManager.Default.UpdateUser(user); 
            } 
            private void BindForm() 
            { 
                MembershipUser user = UserManager.Default.GetUser(); 
                Debug.Assert(user != null); 
                manageProfile.Username = user.UserName;  
            } 
        } 

    This doesn't work: when I check the ProfileSaved event and inspect the current values (not shown above) they are the same as before. If I go to the SF backend however, and change the user profile properties there, they are persisted just fine. So I'm wondering what ~/Sitefinity/Admin/CmsAdmin/Users.aspx does that my code doesn't?

    Any hints on how to get the control to actually save the changed values would be much appreciated. Thanks.

    Kind regards,

    Hardy
  2. Hardy
    Hardy avatar
    21 posts
    Registered:
    27 Sep 2012
    20 May 2009
    Link to this post
    Anyone? I would really appreciate some help on how to persist values using the ManageProfile control. The behavior I described is reproducible in a smaller, stripped down user profile, too, so there must be something I am missing.

    Any hints?

    Regards,

    Hardy
  3. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    20 May 2009
    Link to this post
    Hello Hardy,

    Thank you for writing to us. Could you tell us which Sitefinity version you are using? We could reproduce the problem with one of the versions. This seems to be a problem with our control, not with your implementation, and we will need a bit more time to test and look for a workaround until the next version is out.

    Regards,
    Sonya
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Hardy
    Hardy avatar
    21 posts
    Registered:
    27 Sep 2012
    20 May 2009
    Link to this post
    Thank you, Sonya. I'm using the latest version, 3.6 with SP1 applied. The version number of Telerik.Cms.dll is 3.6.1927.2.

    Let me know if you need to know anything else.

    Regards,

    Hardy
  5. Hardy
    Hardy avatar
    21 posts
    Registered:
    27 Sep 2012
    22 May 2009
    Link to this post
    Hi,

    I have updated the site to version 3.6 SP2 (3.6.1036.2). I'm still experiencing the same behavior, the ManageProfile control is not persisting the changed values. Any hints on how to actually persists the values? Any workarounds if this is indeed a bug in Sitefinity?

    Regards,

    Hardy
  6. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    27 May 2009
    Link to this post
    Hello Hardy,

    We are confirming that this is a Sitefinity bug. We have given you points for reporting this issue with the ManageProfile control.

    However, locally, your control works perfectly despite this bug. I have tested it in different scenarios such as being logged in and being logged out and in both cases it saves the data and I am able to view the changes in the My Profile section for the corresponding user. I have added your code as a user control and with slight modifications (such as removing the data sources since we do not have them), it works perfectly.

    Here is what we tested:
    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="testCustomManageProfile.ascx.cs" Inherits="UserControls_testCustomManageProfile" %> 
    <%@ Register TagPrefix="cc1" Assembly="Telerik.Security" Namespace="Telerik.Security.WebControls" %> 
     
    <cc1:ManageProfile runat="server" ID="manageProfile" Mode="Edit" UsernameIfNoNames="false">  
        <EditTemplate>  
            <h3>Profil bearbeiten</h3>  
            <fieldset>  
                <ul>  
                    <li>  
                        <asp:Label ID="lblSalutation" runat="server" Text="Anrede"/>                  
                    </li>  
                    <li>  
                        <asp:Label ID="lblTitle" runat="server" Text="Titel" AssociatedControlID="Title" />  
                        <asp:TextBox ID="Title" runat="server"></asp:TextBox>  
                    </li>  
                    <li>  
                        <asp:Label ID="lblFirstName" runat="server" Text="Vorname" AssociatedControlID="FirstName" />  
                        <asp:TextBox ID="FirstName" runat="server"></asp:TextBox>  
                    </li>  
                    <li>  
                        <asp:Label ID="lblLastName" runat="server" Text="Nachname" AssociatedControlID="LastName" />  
                        <asp:TextBox ID="LastName" runat="server"></asp:TextBox>  
                    </li>  
                    <li>  
                        <asp:Label ID="lblProfession" runat="server" Text="Berufsbezeichnung" AssociatedControlID="Profession" />  
                        <asp:TextBox ID="Profession" runat="server"></asp:TextBox>  
                    </li>  
                    <li>  
                        <asp:Label ID="lblCountry" runat="server" Text="Land" />                  
                    </li>  
                    <li>  
                        <asp:Label ID="lblLanguage" runat="server" Text="Sprache" AssociatedControlID="Language" />  
                        <asp:TextBox ID="Language" runat="server"></asp:TextBox>  
                    </li>                  
                </ul>  
            </fieldset>  
          </EditTemplate>  
    </cc1:ManageProfile>  
    <asp:Button runat="server" ID="cmdSaveUser" CommandName="Save" OnCommand="cmdSaveUser_Command" Text="Speichern" />  


    .cs
    using System; 
    using System.Diagnostics; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
     
    using Telerik.Security; 
    using Telerik.Security.WebControls; 
     
     
    public partial class UserControls_testCustomManageProfile : System.Web.UI.UserControl 
            protected void Page_Load(object sender, EventArgs e) 
            { 
                if (!Page.IsPostBack) 
                { 
                    manageProfile.Mode = ManageProfile.Modes.Edit; 
                    BindForm(); 
                } 
            } 
     
            protected void cmdSaveUser_Command(object sender, CommandEventArgs e) 
            { 
                MembershipUser user = UserManager.Default.GetUser(); 
                manageProfile.SetProfileProperties(user.UserName); 
                UserManager.Default.UpdateUser(user); 
            } 
            private void BindForm() 
            { 
                MembershipUser user = UserManager.Default.GetUser(); 
                Debug.Assert(user != null); 
                manageProfile.Username = user.UserName; 
            } 

    Could you confirm that exactly this code works (or doesn't work) at your side.

    Sincerely yours,
    Sonya
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Hardy
    Hardy avatar
    21 posts
    Registered:
    27 Sep 2012
    28 May 2009
    Link to this post
    Hi Sonya,

    thank you. I have created a temporary user control, added your code to it, added it to the toolbox, created a page and added the control to it. When I log in, edit a value, save and then refresh the page, the old values are still there. The control is not persisting the values. It *seems* to persist them when I save, because the ASP.NET view state mechanism keeps the text fields populated as they were when I clicked "Save", but after refreshing, the previous values are shown. The database hasn't been updated either.

    Any other ideas? Anything else I should be looking for?

    Kind regards,

    Hardy
  8. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    30 May 2009
    Link to this post
    Hello Hardy,

    I understand your frustration. Let me provide you some more details to explain why this is possible.

    The bug is actually in the default template for the ManageProfile control - it is called DefaultEditTemplate. Your code, as well as MyProfile and Users pages in the administration area actually provide their own templates and they never use this default template. That is why there is no such problem when the ManageProfile control is used outside its default state.

    I tested your control again to make sure it does save the values even after IIS restart, cache clearing, etc.
    I created a brand new project with Sitefinity version 3.6 SP2 (1936). These are my steps:
    1. Created a user control and copy-pasted the code I posted in your forum thread and run the project.
    2. Created a home page and placed a Login control to be able to publicly log into Sitefinity
    3. Created a page and placed your control (modified version) along with a Login View control (to see if and which user is logged in)
    4. Created a new user without saving any optional profile details
    5. On the public side, opened the home page and logged into Sitefinity with that user's credentials
    6. On the public side, opened the second page which contains the user control, and saw the LoginView control showed that the new user is logged in. Filled in the Vorname and NachName fields and clicked on Speichern
    7. On the public side, logged out at the page with the user control. Clicked Ctrl+F5 to clear the browser cache, restarted the IIS, restarted the application.
    8. Logged into the administration with that user's credentials and went to the section MyProfile
    9. The newly-saved FirstName and LastName were displayed in their corresponding fields.

    The only problem I encountered is that when I log out the control still contained the details of the last-logged-in-user. That data needs to be cleared everytime the user is null.

    Here is what I did additionally so that there is no error every time there is no logged-in user (user=null):
    public partial class UserControls_testCustomManageProfile : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                manageProfile.Mode = ManageProfile.Modes.Edit; 
                BindForm(); 
            } 
        } 
     
        protected void cmdSaveUser_Command(object sender, CommandEventArgs e) 
        { 
            MembershipUser user = UserManager.Default.GetUser(); 
            if (user != null
            { 
                manageProfile.SetProfileProperties(user.UserName); 
                UserManager.Default.UpdateUser(user); 
            } 
        } 
        private void BindForm() 
        { 
            MembershipUser user = UserManager.Default.GetUser(); 
            //Debug.Assert(user != null); 
            if (user != null
            { 
                manageProfile.Username = user.UserName; 
            } 
        } 

    The default ManageProfile control will be working in the next Sitefinity release - the default template is fixed for it.

    Please try these steps as well, and if you are still unable to view this behavior, please send me your original project so that we could think of some workaround for you. But, again - the MyProfile and Users sections do work and they use the ManageProfile control so this should not be an issue.

    Waiting for your response.

    Greetings,
    Sonya
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
8 posts, 0 answered