Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating another users profile in VS 2010

Status
Not open for further replies.
Oct 3, 2007
15
US
I have created and asp.net website that has user profiles associated with users authenticated through Active Directory. I can add the profile and view other user profiles without any problem. But if I want to update another users profile it doesn't want to work.

If I hard code the values into the update like below it works fine:

Code:
        Dim userProfile As New ProfileCommon
        userProfile = Profile.GetProfile("username")

        With userProfile
            .FirstName = "asdf"
            .LastName = "dfgh"
        End With

        userProfile.Save()

But if I try to get the updated values from textboxes like below, it won't work.

Code:
        Dim userProfile As New ProfileCommon
        userProfile = Profile.GetProfile("username")

        With userProfile
            .FirstName = txtFname.text.toString
            .LastName = txtLname.Text.ToString
        End With

        userProfile.Save()

What am I doing wrong?

Thanks,
 
is vb case sensitive? that could be 1 problem, but that would throw a compilation error. are you sure the controls contain values?

try this code and set a break point on firstname. step through the code and confirm that first and last name have the expected value.
Code:
var firstname = txtFname.Text
var lastname = txtLname.Text

Dim userProfile = Profile.GetProfile("username")
userProfile.FirstName = firstname
userProfile.LastName = lastname
userProfile.Save()



Jason Meckley
Programmer

faq855-7190
faq732-7259
 
After updating the values in the first and last name textboxes and clicking the update button, I notice in debugging mode the textboxes are keeping their original values. How do I get them to keep the updated variables?
 
Try without the .ToString Function and use the Me Class of the page.

Code:
Dim userProfile As New ProfileCommon = Profile.GetProfile("username")
With userProfile            
   .FirstName = Me.txtFname.Text            
   .LastName = Me.txtLname.Text     
End With
userProfile.Save()

This works on our test system.

HTH

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Me. is redundant that won't change anything, unless he also has a local variable named txtFname/txtLname.

post your markup. if the controls do not contain a runat="server" attribute, that could be the problem.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I figure it out. I needed to put the page load event, which loads the profile into the textboxes, into an if not ispostback statement like below.

Code:
        If Not IsPostBack Then
            Dim p As New ProfileCommon
            p = Profile.GetProfile(Request.QueryString("username"))

            txtEmail.Text = p.Email.ToString
            txtFacility.Text = p.Facility.ToString
            txtFname.Text = p.FirstName.ToString
            txtLname.Text = p.LastName.ToString
            txtUsername.Text = p.UserName.ToString

        End If

thanks,
 
ah, good ol' page life cycle. only in webforms is this a concern ;)

that said, the load event isn't necessarily the proper place for this code. lets assume there is a button on the form the user clicks after updating the first and last name. create a button click event for that button and put your logic there, not the page load event.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Sorry jMeckley, posted without thinking about the Me redundancy.. Look at me, all old hat! (Still maintaining software in VB6 and .Net 1.1)

TigerFan, Nothing like a good postback to scroom up your code.
Well done on figurung it out and thank you for posting your results. Always helps to have solved questions.!

Regards,

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top