Edit Memebership Profile is needed

Dec 17, 2008 at 8:18 PM
Could not find a way Out-of-Box to update the email and security Q&A for the memberships. I created the following very simple page that will allow you to update yout memebership email and the security Q&A. The page uses a masterpage with 2 content area. You may need to change as you need.

I also put the follwoung on the page somewhere to show who is logged in and it puts the edit to this page next to the user name.

<asp:LoginName ID="LoginName" runat="server" FormatString="User: {0} <a href='editProfile.aspx'>edit</a>" />



------editProfile.aspx------------------------------

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="editProfile.aspx.cs" Inherits="eService_editProfile" Title="Company Name: Update eServer Profile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<script runat="server">
MembershipUser u;
public void Page_Load(object sender, EventArgs args)
{
  u = Membership.GetUser(User.Identity.Name);
  if (!IsPostBack)
  {
    EmailTextBox.Text = u.Email;
  }
  if (!IsPostBack)
  {
      question.Text = u.PasswordQuestion;
  }
}

public void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
  try
  {
    u.Email = EmailTextBox.Text;
    Membership.UpdateUser(u);
    Msg.Text = "User e-mail updated.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = e.Message;
  }
}

    public void UpdateQAButton_OnClick(object sender, EventArgs args)
    {
        try
        {
            if (u.ChangePasswordQuestionAndAnswer(pwd.Text, question.Text, answer.Text))
            {
                Msg2.Text = "Question and answer updated";
            }
            else
            {
                Msg2.Text = "Question and answer failed to update";
            }
        }
        catch (System.Configuration.Provider.ProviderException e)
        {
            Msg2.Text = e.Message;
        }
    }
</script>

<form id="Form1" runat="server">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR>

  <table CellPadding="3" border="0">
    <tr>
      <td>E-mail Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton"
                      Text="Update E-mail"
                      OnClick="UpdateEmailButton_OnClick"
                      runat="server" /></td>
    </tr>
  </table>
<p></p>
  <h3>Update Security Question and Answer for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg2" ForeColor="maroon" runat="server" /><BR>

  <table CellPadding="3" border="0">
    <tr>
      <td>Security Question:</td>
      <td><asp:TextBox id="question" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
                                    ControlToValidate="question" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Security Answer:</td>
      <td><asp:TextBox id="answer" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
                                    ControlToValidate="answer" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
        <tr>
      <td>Current Password:</td>
      <td><asp:TextBox TextMode="Password" id="pwd" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server"
                                    ControlToValidate="pwd" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
   
    <tr>
      <td></td>
      <td><asp:Button id="Button1"
                      Text="Update Question and Answer"
                      OnClick="UpdateQAButton_OnClick"
                      runat="server" /></td>
    </tr>
  </table>
</form>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" runat="Server">
    <ul class="list-of-links">
    <li class="current"><a href="eServiceHomePage.aspx">Customer Home Page</a></li>
  <li><a href="ModifyProfile.aspx">My Profile</a></li><br />
  <li><a href="ViewCase.aspx">Create a New Case</a></li>
  <li><a href="ViewCases.aspx">My Service Cases</a></li>
  <li><a href="ChangePassword.aspx">Change Password</a></li>
    </ul>
</asp:Content>

Dec 24, 2008 at 1:47 PM
Edited Dec 24, 2008 at 1:48 PM
Thanks Bill.
I rewrote it a bit to let it work with the Sample Portal:

------editProfile.aspx------------------------------

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Title="Company Name: Update eServer Profile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script runat="server">
MembershipUser u;
public void Page_Load(object sender, EventArgs args)
{
  u = Membership.GetUser(User.Identity.Name);
  if (!IsPostBack)
  {
    EmailTextBox.Text = u.Email;
  }
  if (!IsPostBack)
  {
      question.Text = u.PasswordQuestion;
  }
}

public void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
  try
  {
    u.Email = EmailTextBox.Text;
    Membership.UpdateUser(u);
    Msg.Text = "User e-mail updated.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = e.Message;
  }
}

    public void UpdateQAButton_OnClick(object sender, EventArgs args)
    {
        try
        {
            if (u.ChangePasswordQuestionAndAnswer(pwd.Text, question.Text, answer.Text))
            {
                Msg2.Text = "Question and answer updated";
            }
            else
            {
                Msg2.Text = "Question and answer failed to update";
            }
        }
        catch (System.Configuration.Provider.ProviderException e)
        {
            Msg2.Text = e.Message;
        }
    }
</script>
<div id="pagetitle">
        Update Login-details</div>
<div id="content-container-three-column">
<div id="content-side1-three-column">
    <ul class="list-of-links">
    <li><a href="eServiceHomePage.aspx">Customer Home Page</a></li>
  <li class="current"><a href="ModifyProfile.aspx">My Profile</a></li><br />
  <li><a href="ViewCase.aspx">Create a New Case</a></li>
  <li><a href="ViewCases.aspx">My Service Cases</a></li>
<li><a href="ScheduleService.aspx">Schedule a Service</a></li> 
<li><a href="ViewScheduledServices.aspx">My Scheduled Services</a></li>
    </ul>
</div>
<div id="content-main-three-column">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR>

  <table CellPadding="3" border="0">
    <tr>
      <td>E-mail Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton"
                      Text="Update E-mail"
                      OnClick="UpdateEmailButton_OnClick"
                      runat="server" /></td>
    </tr>
  </table>
<p></p>
  <h3>Update Security Question and Answer for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg2" ForeColor="maroon" runat="server" /><BR>

  <table CellPadding="3" border="0">
    <tr>
      <td>Security Question:</td>
      <td><asp:TextBox id="question" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
                                    ControlToValidate="question" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Security Answer:</td>
      <td><asp:TextBox id="answer" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
                                    ControlToValidate="answer" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
        <tr>
      <td>Current Password:</td>
      <td><asp:TextBox TextMode="Password" id="pwd" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server"
                                    ControlToValidate="pwd" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
   
    <tr>
      <td></td>
      <td><asp:Button id="Button1"
                      Text="Update Question and Answer"
                      OnClick="UpdateQAButton_OnClick"
                      runat="server" /></td>
    </tr>
  </table>
</div>
<div id="content-side2-three-column">
</div>
<div class="clear">
        </div>
    </div>
</asp:Content>