Tracht-Shop Tracht-Shop Feed FriendsPoint.de German Wear.com German Wear.EU
Write an Article Write a Tutorial Add a Fast Code* *Fast Code might be any helpful code with brief comment
Tutorials: ASP .NET C# .NET VB .NET Articles: ASP .NET C# .NET VB .NET Fast Code: ASP .NET C# .NET VB .NET
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.
<div align=center style="margin-top:100px"> <asp:CreateUserWizard ID="WizardCreateUser" runat="server" ContinueDestinationPageUrl="~/Default.aspx" OnCreatedUser="WizardCreateUser_CreatedUser"> <WizardSteps> <asp:CreateUserWizardStep runat="server" > <ContentTemplate> <table border="0"> <tbody> <tr> <td align="center" colspan="2"> <asp:Label ID=top runat=server Text="Sign Up for Your New Account" Font-Bold="True" Font-Size="10pt"></asp:Label> </td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></td> <td align=left> <asp:TextBox ID="UserName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></td> <td align=left> <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label></td> <td align=left> <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label></td> <td align=left> <asp:TextBox ID="Email" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label></td> <td align=left> <asp:TextBox ID="Question" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label></td> <td align=left> <asp:TextBox ID="Answer" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan=2> <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="10pt">Optional Informations</asp:Label> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label1" runat="server" >First Name:</asp:Label></td> <td align=left> <asp:TextBox ID="TextBoxFirstName" runat="server"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label2" runat="server" >Last Name:</asp:Label></td> <td align=left> <asp:TextBox ID="TextBoxLastName" runat="server"></asp:TextBox> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="CreateUser"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color: red"> <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> </td> </tr> </tbody> </table> </ContentTemplate> </asp:CreateUserWizardStep> <asp:CompleteWizardStep runat="server" /> </WizardSteps> </asp:CreateUserWizard> </div>
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> .
<profile enabled="true"> <properties> <add name="FirstName"/> <add name="LastName"/> </properties> </profile>
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.
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
31/12/2007 08:10:07 UTC
17/01/2008 02:32:07 UTC
18/01/2008 08:37:07 UTC
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
29/12/2008 12:09:29 UTC
10/01/2009 04:36:46 UTC
16/01/2009 02:41:01 UTC
09/02/2009 20:59:37 UTC
21/02/2009 15:19:27 UTC
This thing works great!! I have a quick question though. when it write to the database it combines the First and Last name along with any other fields you want to collect info such as Account number in the column PropertyValuesString in the aspnet_profile table. is there a way to separate them out so that it would be easier to query against and place the collected data in it's own column?
30/04/2009 08:11:55 UTC