View Single Post
  #10 (permalink)  
Old March 9th, 2006, 05:31 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi again,

Sorry for my late response... Was kinda busy. Anyway, I'll try to address your questions / concerns:
quote:I keep reading about custom providers, do i need to create my own or do this a whole different way? All i want to do is allow the user to register giving three extra pieces of information which will be stored and then the mobile number used for sending information to the user at a later date.
You could, but you don't need it. Basically, you only need to build a custom provider if you want to target a different data source or schema. So, if you have existing users in a SQL Server database with its own schema, or want to target, say, Oracle, then you need to write a custom provider.
From what I can see, your requirements don't need this; the default membership, in combination with the Profiles feature should be enough.
quote:i'm not sure I understand what you mean, are you saying that i don't need to put the MobileNumber in the profile in web.config? if so where would i put it instead as i need it to be added.
You do need to put in the Web.config file, or otherwise it won't be available in the Profile. What happens is that when you add a property in the config file, .NET will compile a class on the fly with the properties in the config file. That's why you can have code like this: Profile.MobileNumber and get Intelli Sense helping you with the code.
quote:Also what type would you suggest that the variable be if not an integer?
It's unlikely you'll want to do calculations with the Mobile Number, so a String is much more logical. What do you do when people add something like +44 (43) 38378346?? That may be a valid number, but not a valid Integer.
quote:It seems that whatever way i try to do myProfile.MobileNumber = MobileNumber.text it always says that MobileNumber is not declared.even if i tried to cast it or convert it in some way. is there something i need to put at the top that the page inherits or a certain class that it needs.
Does it say that on the property you're trying to access? (e.g. txtMobileNumer.Text) or on the Profile property (e.g. myProfile.MobileNumber)?

In the first case, this happens when you try to access something like txtMobileNumber directly. You say you have it declared, and you're right. However, it's not declared at the Page level, so you can't access it directly. Instead, you'll need to use the code you posted earlier, and that I fixed in a previous post. That is, use FindControl on the CreateUserWizard and then cast it to a TextBox and access the Text property.
quote:All the pages i've seen on this topic state that all i would need to do is add the variable in the profile in webconfig, add a textbox of the variable in the userwizard and then put profile.variable = variable.text but it just doesn't work for me.
Almost; that's how it normally works in other pages. However, because you're using a CreateUserWizard control you need to "find" the MobileNumber text box control and get its text.
quote:I got it to compile by doing it but which table does the mobilenumber go into or do i need to specify it somehow as i can't find it where the data has been inserted. Do you need to specify where the new data would go in the membership tables?
The additional properties are not stored in a separate column in the Membership user table. So, you won't find a MobileNumber column in that table. Instead, the info is stored in aspnet_Profiles. This table has a number of columns. One column holds the list of available properties and their length. An other holds the entire profile data in quite an awkward format. You won't be able to see how the data is stored directly; you'll need the other column to understand the format.
quote:This might be a stupid suggestion but could i not just add an extra column called mobilenumber to the membership column and create a insert statement to insert the contents of the mobile number textbox when the user is created?
I have been taught there are no stupid questions; only stupid answers... ;) I'll try no to supply one...
You could do that, but it's not worth the trouble. You'd need to create a class that inherits from MembershipUser and add additional properties. However, this brings a few problems of its own. First, you'd need to implement behavior to save the additional properties your class gets. Second, you'd need to cast the MembershipUser to your MemberShipUser class wherever you need to access the additional properties. Again, in your situation you don't need all of this.

On my own website, I have implemented what I described here: used the standard CreateUserWizard control, customized the template and added a bunch of properties for address data, like city and country. That data is stored in the Profile whenever someone signs up. Works fine, with exactly the code I posted and described earlier. You can see for your self by signing up for an account (just follow the What's This? link at the bottom of this post and then click the Login tab on my website)

Scott Guthrie has pasted a nice blog post about this, including sample code. You can find the item here: How to add a Login, Roles and Profile system to an ASP.NET 2.0 app in only 24 lines of codeBasically, he shows you exactly what you need, with only 24 lines of hand written code....


Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Thoughtless by KoRn (Track 6 from the album: Untouchables) What's This?