German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Create a User Profile in Regisration Page

Written by omerkamal on Dec 30, 2006
How to create user profile the time they get register?

Introducation:

I saw many questions in differnt forums about how to handel the Profile creation at when users register. Most users now knows about Login and Membership new Controles in ASP .NET 2.0 . But how to handle this special event is kind of different approach.

Explanation:

We will create a Registration Page where users will also provide us some optional entries. This is completly managed by ASP .NET 2.0 Profiling. Let us do it step by step.

  • Create a New Page Call it "GetRegistered.aspx" also select "Place code id separate file"
  • Open the Design view of the page
  • Throw the "CreateUserWizard" on the page
  • Click the Wizard from Top right Corner small errow ( this is where we can edit every server controle)
  •  Click the Link "Customize Create User Step" .
  •  Now open the source view of page. You noticed that it created alot of code in your page.
  •  Add some  more code to the Wizard as shown in the code below ( in bold)


ContinueDestinationPageUrl="~/Default.aspx" OnCreatedUser="WizardCreateUser_CreatedUser">





















































User Name:


ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUser">*

Password:


ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUser">*

Confirm Password:


ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
ValidationGroup="CreateUser">*


E-mail:


ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUser">*

Security Question:


ErrorMessage="Security question is required." ToolTip="Security question is required."
ValidationGroup="CreateUser">*


Security Answer:


ErrorMessage="Security answer is required." ToolTip="Security answer is required."
ValidationGroup="CreateUser">*


Optional Informations

First Name:



Last Name:



ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUser">









 Now, Right Click the page and go to "Code view" of the Page. add this code to the Page.

protected void WizardCreateUser_CreatedUser(object sender, EventArgs e)
{
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(WizardCreateUser.UserName, true);

p.FirstName = ((TextBox)WizardCreateUser.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFirstName")).Text;

p.LastName = ((TextBox)WizardCreateUser.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxLastName")).Text;

p.Save();
}

 Ok, still one more thing to be done. add these lines to you Web.config . This block of code will come between <system.web>   system.web> .






 Ok ,now you can view the page in the Browser. Create a new user. To view Users Profile you need to Create a Page. Call this Page "UserPrifile.aspx" .

How will you create UserPrifile page? See our Article Profiling in ASP .NET 2.0.

Visitors/Readers Comments
(for questions please use The Forum)



omerkamal

For VB remove "OnCreatedUser="WizardCreateUser_CreatedUser" " and add the following code in codebehind.

Protected Sub WizardCreateUser_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles WizardCreateUser.CreatedUser
Dim p As ProfileCommon
p = CType(ProfileCommon.Create(WizardCreateUser.UserName, True), ProfileCommon)

p.FirstName = CType(WizardCreateUser.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFirstName"), TextBox).Text

p.LastName = CType(WizardCreateUser.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxLastName"),TextBox).Text

p.Save()

End Sub

30/12/2006 06:25:49 UTC

stevem
great stuff

31/12/2007 08:10:07 UTC

First
thanks so much that is very nice

17/01/2008 02:32:07 UTC

Felipe Lopez
So far I haven't see such GOOD explanation like the one you present.

18/01/2008 08:37:07 UTC

Santosh

this is great idea to write this type of program so that new developer can understand the code.
 

13/09/2008 05:05:31 UTC

Justin Reeves
 Genius! I have spent the last 10 hours going through various articles by Scott Gu & other respected ASP.net guys but your explanation is the best and most logical. THANK YOU :)

29/12/2008 12:09:29 UTC

Denish Rana
Not Working

10/01/2009 04:36:46 UTC

Ryan
Recieving Errors

16/01/2009 02:41:01 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)