Home > ASP.Net > Allow Users to Change Their Email Address using Membership

Allow Users to Change Their Email Address using Membership


Hi

try this example to Allow Users to Change Their Email Address using Membership :-

in code behind :-

protected void Page_Load(object sender, EventArgs e)
{
    //add theses lines
    if (!IsPostBack)
   {
      MembershipUser user = Membership.GetUser();
       if (user != null)
      {
         txtEmail.Text = user.Email;
      }
   }
}
Then, we need to add the method that fires when the Change Email button is clicked.

//add this methodprotected void btnEmail_Click(object sender, EventArgs e)
{
   if (IsValid)
   {
      MembershipUser user = Membership.GetUser();
       if (user != null && txtEmail.Text != user.Email)
       {
         user.Email = txtEmail.Text;
          try
         {
            Membership.UpdateUser(user);
            lblEmailChangeSuccess.Text = "Your email address was successfully changed.";
         }
         catch (ProviderException)
         {
            lblEmailChangeFail.Text = "A user with that email address already exists. Your address was not changed.";
         }
      }
   }
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: