More in this section

Forums / Developing with Sitefinity / phone and email aren't updated

phone and email aren't updated

4 posts, 0 answered
  1. Dwayne Epps
    Dwayne Epps avatar
    6 posts
    Registered:
    04 May 2010
    21 May 2010
    Link to this post
    I've created a custom user control to manage a user profile:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="EditProfile.ascx.cs" Inherits="CompassLearning_Controls_EditProfile" %>
    <%@ Register Assembly="Telerik.Security" Namespace="Telerik.Security.WebControls" TagPrefix="cc1" %>    
         
    <cc1:ManageProfile ID="manageProfile" runat="server" Mode="edit" UsernameIfNoNames="false">   
        <EditTemplate>   
            <h2>Edit Profile</h2>
            <table cellpadding="0" cellspacing="0" border="0" width="700">
                <tr>
                    <td align="right"><asp:Label ID="lblFirstName" runat="server" Text="First name" TargetID="FirstName"></asp:Label></td>
                    <td><asp:TextBox ID="FirstName" runat="server"></asp:TextBox> </td>
                </tr>
                <tr>
                    <td align="right"><asp:Label ID="lblLastName" runat="server" Text="Last name" TargetID="LastName"></asp:Label></td>
                    <td><asp:TextBox ID="LastName" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="right"><asp:Label ID="lblPosition" runat="server" Text="Position" TargetID="Position"></asp:Label></td>
                    <td><asp:TextBox ID="Position" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="right"><asp:Label ID="lblEmail" runat="server" Text="Email" TargetID="Email"></asp:Label></td>
                    <td><asp:TextBox ID="Email" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="right"><asp:Label ID="lblPhone" runat="server" Text="Phone" TargetID="Phone_Value"></asp:Label></td>
                    <td><asp:TextBox ID="Phone" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><asp:LinkButton ID="cmdSaveUser" Text="Save" CommandName="Save" OnCommand="cmdSaveUser_Command" runat="server"></asp:LinkButton></td>
                </tr>
            </table>  
        </EditTemplate>   
    </cc1:ManageProfile>

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                MembershipUser user = UserManager.Default.GetUser();
      
                this.manageProfile.Mode = Telerik.Security.WebControls.ManageProfile.Modes.Edit;
                this.manageProfile.Username = user.UserName;
            }  
        }
      
        protected void cmdSaveUser_Command(object sender, CommandEventArgs e)
        {
            try
            {
                MembershipUser user = UserManager.Default.GetUser();
                this.manageProfile.SetProfileProperties(user.UserName);
                UserManager.Default.UpdateUser(user);
            }
            catch
            {
            }
        }

    "FirstName", "LastName" and "Position" get updated, but "Email" and "Phone" do not get updated.

    I haven't been able to determine why?

    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 May 2010
    Link to this post
    Hi Dwayne Epps,

    The email is membership user data and you cannot use ProgfileManager to set it. You should use user.Email="some value " in your code

    If the Phone property value is declared as shown below

    <group name="Phone">
      <add name="Value" />
      <add name="Type" />
    </group>


    The ID of your TextBox should be Phone_Value

    <td align="right"><asp:Label ID="lblPhone" runat="server" Text="Phone" TargetID="Phone_Value"></asp:Label></td>
    <td><asp:TextBox ID="Phone_Value" runat="server"></asp:TextBox></td>


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Dwayne Epps
    Dwayne Epps avatar
    6 posts
    Registered:
    04 May 2010
    21 May 2010
    Link to this post

    The phone field is updating correctly now, but I'm still not able to update the email field.

    This is the code I'm using to try and update the email field:

    protected void cmdSaveUser_Command(object sender, CommandEventArgs e)
       {
           try
           {
               TextBox txtEmail = (TextBox)manageProfile.FindControl("Email");
               string email = txtEmail.Text;
               MembershipUser user = UserManager.Default.GetUser();
               user.Email = email;
               this.manageProfile.SetProfileProperties(user.UserName);
               UserManager.Default.UpdateUser(user);
           }
           catch
           {
           }
       }

    I use FindControl to get a reference to the email textbox control within teh manageProfile webcontrol.
    I set a string value to the email textbox text property.
    I assign user.Email to the email string.

    I'm not getting any errors, but email is not updated.  What am I missing?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2010
    Link to this post
    Hello Dwayne Epps,

    You should access the Email Textbox from the container of ManageUsers control, not from manageProfile control which contains profile data.

    void manageUsers_UpdatedUser(object sender, EventArgs e)
    {
     
        Telerik.Security.WebControls.ManageUsers.EditContainer eContainer = manageUsers.GetCurrentContainer() as Telerik.Security.WebControls.ManageUsers.EditContainer;
        if (eContainer != null)
        {
            string email = eContainer.EmailTextBox.Text;
        }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered