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)
<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.
|