By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Profile. For the Gurus out there. What is wrong here?!

P: n/a
Hello,

In my Page's VB.NET code I am changing the value of the Profile
property NAME.

Profile.Name = tbName.Text

However, I need to change this property value from a class in my
App_Code so I did:

' Get current username
Dim username As String = HttpContext.Current.User.Identity.Name

' Get user profile
Dim userProfile As ProfileCommon = CType(HttpContext.Current.Profile,
ProfileCommon).GetProfile(username)

' Define profile properties
userProfile.Name = "NewName"

' Save user profile
userProfile.Save()

I tried everything I could think off and I read everything I found.

This should work!

Please, does anyone has any idea? I am on this for 2 days.

The fact that the form is inside an Asp.Net AJAX Update Panel could
have something to do with it?

Thanks,

Miguel

Mar 6 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>
This should work!

Please, does anyone has any idea? I am on this for 2 days.

The fact that the form is inside an Asp.Net AJAX Update Panel could
have something to do with it?
I've got an article just for that...
Have a look at:
http://eduzine.edujini-labs.com/arch...n-ASP.Net.html
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Mar 6 '07 #2

P: n/a
On Mar 6, 6:28 pm, "MasterGaurav \(www.edujini-labs.com\)"
<gaurav.vaish.nos...@nospam.gmail.comwrote:
This should work!
Please, does anyone has any idea? I am on this for 2 days.
The fact that the form is inside an Asp.Net AJAX Update Panel could
have something to do with it?

I've got an article just for that...
Have a look at:
http://eduzine.edujini-labs.com/arch...o-work-with-cu...

--
Happy Hacking,
Gaurav Vaish |http://www.mastergaurav.comwww.eduji...ujini-labs.com
-----------------------------------------
Hi,

I am not sure if this would work for me.

I am using various sub classes and properties.
Anyway, I think the best thing to do is to post my code:

I have everything in Class inside App_Code named Profile:

1 ' -- [Import Namespaces]
-------------------------------------------
2 Imports Microsoft.VisualBasic
3
4 ' -- [Namespace] -------------------------------------------
5
6 ' MyWebSite
7 Namespace MyWebSite
8
9 ' -- [Property Classes]
-------------------------------------------
10
11 ' Contacts
12 <Serializable()_
13 Public Class Contacts
14
15 ' -- [Properties] -------------------------------------------
16
17 ' City
18 Private _City As String
19 Public Property City() As String
20 Get
21 Return _City
22 End Get
23 Set(ByVal value As String)
24 _City = value
25 End Set
26 End Property ' City
27
28 ' Mobile
29 Private _Mobile As String
30 Public Property Mobile() As String
31 Get
32 Return _Mobile
33 End Get
34 Set(ByVal value As String)
35 _Mobile = value
36 End Set
37 End Property ' Mobile
38
39 ' Street
40 Private _Street As String
41 Public Property Street() As String
42 Get
43 Return _Street
44 End Get
45 Set(ByVal value As String)
46 _Street = value
47 End Set
48 End Property ' Street
49
50 End Class ' Contacts
51
52 ' Options
53 <Serializable()_
54 Public Class Options
55
56 ' -- [Properties] -------------------------------------------
57
58 ' Newsletter
59 Private _Newsletter As Boolean
60 Public Property Newsletter() As Boolean
61 Get
62 Return _Newsletter
63 End Get
64 Set(ByVal value As Boolean)
65 _Newsletter = value
66 End Set
67 End Property ' Newsletter
68
69 End Class ' Options
70
71 ' Personal
72 <Serializable()_
73 Public Class Personal
74
75 ' -- [Properties] -------------------------------------------
76
77 ' Birthdate
78 Private _Birthdate As DateTime
79 Public Property Birthdate() As DateTime
80 Get
81 Return _Birthdate
82 End Get
83 Set(ByVal value As DateTime)
84 _Birthdate = value
85 End Set
86 End Property ' Birthdate
87
88 ' Name
89 Private _Name As String
90 Public Property Name() As String
91 Get
92 Return _Name
93 End Get
94 Set(ByVal value As String)
95 _Name = value
96 End Set
97 End Property ' Name
98
99 End Class ' Personal
100
101
102 ' -- [Classes] -------------------------------------------
103
104 ' Profile
105 Public Class Profile
106
107 ' -- [Methods] -------------------------------------------
108
109 ' Create
110 Public Overloads Shared Sub Create(ByVal user As
MembershipUser, _
111 ByVal contacts As
Contacts, _
112 ByVal options As Options,
_
113 ByVal personal As
Personal)
114
115 ' Create profile
116 Dim userProfile As ProfileCommon =
CType(ProfileCommon.Create(user.UserName, True), ProfileCommon)
117
118 ' Define profile properties
119 With userProfile
120 .Contacts = contacts
121 .Options = options
122 .Personal = personal
123 End With
124
125 ' Save user profile
126 userProfile.Save()
127
128 End Sub ' Create
129
130 ' Update
131 Public Overloads Shared Sub Update(ByVal contacts As
Contacts, _
132 ByVal options As Options,
_
133 ByVal personal As
Personal)
134
135 ' Get current username
136 Dim username As String =
HttpContext.Current.User.Identity.Name
137
138 ' Get user profile
139 Dim userProfile As ProfileCommon =
CType(HttpContext.Current.Profile, ProfileCommon).GetProfile(username)
140
141 ' Initialize user profile
142 CType(HttpContext.Current.Profile,
ProfileCommon).Initialize(username, True)
143
144 ' Define profile properties
145 With userProfile
146 .Contacts = contacts
147 .Options = options
148 .Personal = personal
149 End With
150
151 ' Save user profile
152 userProfile.Save()
153
154 End Sub ' Update
155
156 End Class ' Profile
157
158 End Namespace ' MyWebSite
Then I call the update function as follows:

1 ' Try to update user profile
2 Try
3
4 ' Create and define contacts properties
5 Dim userContacts As New Contacts
6 With userContacts
7 .City = tbCity.Text
8 .Mobile = tbMobile.Text
10 .Street = tbStreet.Text
11 End With
12
13 ' Create and define options properties
14 Dim userOptions As New Options
15 With userOptions
16 .Newsletter = cbNewsletter.Checked
17 End With
18
19 ' Create and define personal properties
20 Dim userPersonal As New Personal
21 With userPersonal
22 .Birthdate = New
Date(ddlYearOfBirth.SelectedItem.Value,
ddlMonthOfBirth.SelectedItem.Value, ddlDayOfBirth.SelectedItem.Value)
24 .Name = tbName.Text
25 End With
26
27 ' Update user profile
28 MyWebSite.Profile.Update(userContacts, userOptions,
userPersonal)
29
30 Catch ex As Exception
31
32 End Try

Well, I removed a lot of properties so the code would be smaller.

But basically this is it.

I really can't figure what I might be doing wrong.

Thank You for Helping me,

Miguel

Mar 6 '07 #3

P: n/a
I am not sure if this would work for me.
>
I am using various sub classes and properties.
Will work without any problems.
I use this technique very heavily.
I really can't figure what I might be doing wrong.

Thank You for Helping me,
What's the problem that you're facing... you just said that "it does not
work" but did not say "what happens"?
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------

Mar 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.