Page view counter

Pulling Profile Data

Last post 08-12-2008 12:43 PM by kmj2384. 8 replies.

Sort Posts:

  • Pulling Profile Data

    08-05-2008, 9:17 PM
    • Loading...
    • kmj2384
    • Joined on 03-31-2008, 7:59 PM
    • Posts 211
    • Points 74

    I have a profile page on my website that displays profile data as well as can update profile data.  I would like members to be able to see their current email address in the "current profile" section.  However, the email address is stored in the SQL database table aspnet_Membership (using the standard database created by visual web developer 2008).  Is there a way to access this information for the users to see on their profile section?  I know how to pull the rest of the data, ie:

    If Not String.IsNullOrEmpty(Profile.address) Then

    address.Text = Profile.address

    End If

    but theres an error when you try to pull the email:

    If Not String.IsNullOrEmpty(Membership.email) Then

    email.Text = Profile.email

    End If

    ('email' is not a member of 'System.Web.Security.Membership.)

    Thanks for any help!

    Filed under: ,
  • Re: Pulling Profile Data

    08-05-2008, 10:26 PM
    Answer
    • Loading...
    • RedRaiders07
    • Joined on 06-05-2008, 4:59 PM
    • Hyannis, MA, USA
    • Posts 29
    • Points 164

     You first need to access the current MembershipUser to get the email.

    To get the e-mail:

    Membership.GetUser().Email

     

    To set the e-mail when the user clicks save:

    Dim user as MembershipUser = Membership.GetUser()

    user.Email = email.Text

    Membership.UpdateUser(user)

  • Re: Pulling Profile Data

    08-06-2008, 6:24 PM
    • Loading...
    • kmj2384
    • Joined on 03-31-2008, 7:59 PM
    • Posts 211
    • Points 74

    Hi, I put in the code exactly as you said:

    If Not String.IsNullOrEmpty(Membership.GetUser().Email) Then

    Dim user As MembershipUser = Membership.GetUser()

    user.Email = email.Text

    End If

    and now I'm getting this error:

    System.NullReferenceException: Object reference not set to an instance of an object.

    Line 30:             If Not String.IsNullOrEmpty(Membership.GetUser().Email) Then

  • Re: Pulling Profile Data

    08-11-2008, 2:46 AM
    Answer

    Hi,

    I suggest you check if GetUser() method returns null before using it. For example:

    Dim u As MembershipUser = Membership.GetUser(User.Identity.Name)
    If u IsNot Nothing Then
        u.Email = EmailTextBox.Text
        Membership.UpdateUser(u)
    End If

    For more information, see http://msdn.microsoft.com/en-us/library/40w5063z.aspx

     

    I look forward to hearing from you.

    Thomas Sun
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Re: Pulling Profile Data

    08-11-2008, 4:06 PM
    • Loading...
    • kmj2384
    • Joined on 03-31-2008, 7:59 PM
    • Posts 211
    • Points 74

    Hi,

    I looked over the code you posted as well as the link.  I put the code in like this:

    Dim u As MembershipUser = Membership.GetUser(User.Identity.Name)

    If u IsNot Nothing Then

    u.Email = email.Text

    Membership.UpdateUser(u)

    and am now getting this error:

    System.ArgumentException: The parameter 'Email' must not be empty.
    Parameter name: Email

    Line 32:                 u.Email = email.Text
    Line 33:                 Membership.UpdateUser(u)
    Line 34:
    Line 35:             End If

    I'm not sure what that means, do you have anymore insight on the matter?  Thank you very much.

  • Re: Pulling Profile Data

    08-11-2008, 9:54 PM
    • Loading...
    • RedRaiders07
    • Joined on 06-05-2008, 4:59 PM
    • Hyannis, MA, USA
    • Posts 29
    • Points 164

    The error message is saying that you passed an empty email to the UpdateUser method. You should also check to make sure that email.Text has a value and is in correct format. I'll leave the format checking as an exercise for you.

     If u IsNot Nothing AndAlso email.Text.Length > 0 Then

    u.Email = email.Text

    Membership.UpdateUser(u)

    End If

    Make sure that the email TextBox is not being cleared out during postback.
  • Re: Pulling Profile Data

    08-11-2008, 10:53 PM
    • Loading...
    • kmj2384
    • Joined on 03-31-2008, 7:59 PM
    • Posts 211
    • Points 74

    Sorry, I should have been more specific in my last post.  I'm getting the error from my last post when I try to login to my site or am logged in and go to the update profile page.

    Also, to give a little background on the update profile page, when you are logged in it pulls information like address, username, city, etc from the aspnet_Profile Table.

    Since email is not stored in this table, I'm trying to have this code grab the registered email from aspnet_Membership table, and that's the part I'm stuck on.

  • Re: Pulling Profile Data

    08-12-2008, 10:35 AM
    Answer
    • Loading...
    • RedRaiders07
    • Joined on 06-05-2008, 4:59 PM
    • Hyannis, MA, USA
    • Posts 29
    • Points 164

     Oh ok, we have this backwards then. I thought you were having trouble updating the EMail in the Membership data store.

     To pull the email:

    Dim u As MembershipUser = Membership.GetUser()

    If u IsNot Nothing Then

    email.Text = u.Email.toString

    End If

  • Re: Pulling Profile Data

    08-12-2008, 12:43 PM
    • Loading...
    • kmj2384
    • Joined on 03-31-2008, 7:59 PM
    • Posts 211
    • Points 74

    Perfect!  Thank you for walking me through that.

Page 1 of 1 (9 items)