HOW TO:自訂 ASP.NET CreateUserWizard 控制項
更新:2007 年 11 月
您可以使用 CreateUserWizardStep 和 CompleteWizardStep 範本,自訂 CreateUserWizard 控制項的內容。透過指定範本的內容,可以指定本身包含控制項的自訂使用者介面 (UI),CreateUserWizard 控制項會使用這些控制項收集新使用者的資訊,以及指定的其他控制項資訊 (如需 CreateUserWizard 控制項可以使用的控制項清單,請參閱自訂 ASP.NET 登入控制項的外觀)。
此外,由於 CreateUserWizard 控制項是繼承自 Wizard 類別,您可以將自己的自訂步驟加入至 CreateUserWizard 控制項。如需 Wizard 控制項的詳細資訊,請參閱Wizard Web 伺服器控制項概觀。
注意事項: |
---|
您也可以使用主題和樣式屬性 (Property),自訂 CreateUserWizard 控制項的外觀。如需詳細資訊,請參閱 ASP.NET 佈景主題和面板概觀和 CreateUserWizard 控制項的屬性。 |
若要自訂 CreateUserWizard 步驟
使用下列語法將 CreateUserWizard 控制項放在網頁上:
<asp:CreateUserWizard ID="CreateUserWizard1" Runat="server"> <WizardSteps> <asp:CreateUserWizardStep > </asp:CreateUserWizardStep> <asp:CompleteWizardStep > </asp:CompleteWizardStep> </WizardSteps> </asp:CreateUserWizard>
若要自訂使用者帳戶建立步驟,請在 <asp:CreateUserWizardStep> 項目內建立 <ContentTemplate> 項目。在範本內,新增標記和控制項,以定義收集所需使用者資訊的 UI 配置和內容。
注意事項: 如果成員資格提供者使用自訂成員擴充 MembershipProvider 類別,則必須加入所有控制項,以收集成員資格提供者建立新使用者所需的自訂資訊。如需詳細資訊,請參閱 CreateUserWizardStep。
下列程式碼範例會顯示 CreateUserStep 屬性,其中包括可讓使用者指定其他選項的 CheckBox 控制項。
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" > <ContentTemplate> <table border="0" style="font-size: 100%; font-family: Verdana"> <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Sign Up for Your New Account</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" AssociatedControlID="UserName"> User Name:</asp:Label></td> <td> <asp:TextBox ID="UserName" ></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" AssociatedControlID="Password"> Password:</asp:Label></td> <td> <asp:TextBox ID="Password" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" AssociatedControlID="ConfirmPassword"> Confirm Password:</asp:Label></td> <td> <asp:TextBox ID="ConfirmPassword" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" AssociatedControlID="Email"> E-mail:</asp:Label></td> <td> <asp:TextBox ID="Email" ></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" AssociatedControlID="Question"> Security Question:</asp:Label></td> <td> <asp:TextBox ID="Question" ></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" AssociatedControlID="Answer"> Security Answer:</asp:Label></td> <td> <asp:TextBox ID="Answer" ></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="CreateUserWizard1"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color: red"> <asp:Literal ID="ErrorMessage" EnableViewState="False"></asp:Literal> </td> </tr> </table> <asp:CheckBox ID="SubscribeCheckBox" Checked="True" Text="Send me a monthly newsletter." /> <br /> <asp:CheckBox ID="ShareInfoCheckBox" Checked="True" Text="Share my information with partner sites." /> </ContentTemplate> </asp:CreateUserWizardStep>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" > <ContentTemplate> <table border="0" style="font-size: 100%; font-family: Verdana"> <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Sign Up for Your New Account</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" AssociatedControlID="UserName"> User Name:</asp:Label></td> <td> <asp:TextBox ID="UserName" ></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" AssociatedControlID="Password"> Password:</asp:Label></td> <td> <asp:TextBox ID="Password" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" AssociatedControlID="ConfirmPassword"> Confirm Password:</asp:Label></td> <td> <asp:TextBox ID="ConfirmPassword" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" AssociatedControlID="Email"> E-mail:</asp:Label></td> <td> <asp:TextBox ID="Email" ></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" AssociatedControlID="Question"> Security Question:</asp:Label></td> <td> <asp:TextBox ID="Question" ></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" AssociatedControlID="Answer"> Security Answer:</asp:Label></td> <td> <asp:TextBox ID="Answer" ></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="CreateUserWizard1"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color: red"> <asp:Literal ID="ErrorMessage" EnableViewState="False"></asp:Literal> </td> </tr> </table> <asp:CheckBox ID="SubscribeCheckBox" Checked="True" Text="Send me a monthly newsletter." /> <br /> <asp:CheckBox ID="ShareInfoCheckBox" Checked="True" Text="Share my information with partner sites." /> </ContentTemplate> </asp:CreateUserWizardStep>
若要自訂完成步驟,請在 <asp:CompleteWizardStep> 項目中建立 <ContentTemplate> 項目。在範本內,新增標記和控制項,以定義顯示確認訊息和可選擇性地允許使用者巡覽以繼續的 UI 配置和內容(您必須提供控制項才能收集成員資提供者需要的資訊,以建立新的使用者帳戶。如需詳細資訊,請參閱CompleteWizardStep)。
下列程式碼範例會顯示 CompleteStep 屬性,這個屬性會參考前一個範例的 CheckBox 控制項。
<asp:CompleteWizardStep ID="CompleteWizardStep1" > <ContentTemplate> <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" > <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;"> Complete</td> </tr> <tr> <td> Your account has been successfully created.<br /> <br /> <asp:Label ID="SubscribeLabel" Text="You have elected to receive our monthly newsletter."></asp:Label><br /> <br /> <asp:Label ID="ShareInfoLabel" Text="You have elected to share your information with partner sites."></asp:Label></td> </tr> <tr> <td align="right" colspan="2"> <asp:Button ID="ContinueButton" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue" Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" /> </td> </tr> </table> </ContentTemplate> </asp:CompleteWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" > <ContentTemplate> <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" > <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;"> Complete</td> </tr> <tr> <td> Your account has been successfully created.<br /> <br /> <asp:Label ID="SubscribeLabel" Text="You have elected to receive our monthly newsletter."></asp:Label><br /> <br /> <asp:Label ID="ShareInfoLabel" Text="You have elected to share your information with partner sites."></asp:Label></td> </tr> <tr> <td align="right" colspan="2"> <asp:Button ID="ContinueButton" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue" Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" /> </td> </tr> </table> </ContentTemplate> </asp:CompleteWizardStep>
加入程式碼以參考其他控制項。例如,處理 CreatingUser 事件可讓您輸入程式碼,以便於建立新使用者帳戶之前收集、驗證和修改資訊。
下列程式碼範例會顯示 CreatedUser 事件的處理常式,這個處理常式會參考先前範例的 CheckBox 控制項,並將這些控制項加入至新建立之使用者帳戶的 Comment 屬性。您需要將 OnCreatedUser 屬性 (Attribute) 加入至頁面上的 CreateUserWizard 控制項,這個頁面會參考 CreatedUser 事件的處理常式 (例如,OnCreatedUser="CreateUserWizard1_CreatedUser")。
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) ' Determine the checkbox values. Dim subscribeCheckBox As CheckBox = _ CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox"), CheckBox) Dim shareInfoCheckBox As CheckBox = _ CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox"), CheckBox) Dim userNameTextBox As TextBox = _ CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox) Dim user As MembershipUser = Membership.GetUser(userNameTextBox.Text) User.Comment = "Subscribe=" & subscribeCheckBox.Checked.ToString() & "&" & _ "ShareInfo=" & shareInfoCheckBox.Checked.ToString() Membership.UpdateUser(user) ' Show or hide the labels based on the checkbox values. Dim subscribeLabel As Label = _ CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel"), Label) Dim shareInfoLabel As Label = _ CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel"), Label) subscribeLabel.Visible = subscribeCheckBox.Checked shareInfoLabel.Visible = shareInfoCheckBox.Checked End Sub
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { // Determine the checkbox values. CheckBox subscribeCheckBox = (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox"); CheckBox shareInfoCheckBox = (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox"); TextBox userNameTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"); MembershipUser user = Membership.GetUser(userNameTextBox.Text); user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" + "ShareInfo=" + shareInfoCheckBox.Checked.ToString(); Membership.UpdateUser(user); // Show or hide the labels based on the checkbox values. Label subscribeLabel = (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel"); Label shareInfoLabel = (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel"); subscribeLabel.Visible = subscribeCheckBox.Checked; shareInfoLabel.Visible = shareInfoCheckBox.Checked; }
若要加入精靈步驟
將 <asp:WizardStep> 項目加入至 CreateUserWizard 控制項的 <WizardSteps> 區段。在自訂的 CreateUserWizard 控制項將使用的其他精靈步驟中,加入任何控制項和標記。
例如,下列程式碼範例會顯示要在 CreateUserWizard 控制項 (包括可讓使用者輸入使用者名稱的文字方塊控制項) 之 CreateUserStep 前加入的步驟。將檢查使用者名稱,以確定該名稱不在成員資格資料庫中。
<asp:WizardStep ID="CreateUserWizardStep0" > <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" > <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Select an Account Name</td> </tr> <tr> <td> <asp:Label ID="AccountNameLabel" AssociatedControlID="SearchAccount" > Account Name:</asp:Label> <asp:TextBox ID="SearchAccount" ></asp:TextBox><br /> <asp:Label ID="SearchAccountMessage" ForeColor="red" /> </td> </tr> </table> </asp:WizardStep>
<asp:WizardStep ID="CreateUserWizardStep0" > <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" > <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Select an Account Name</td> </tr> <tr> <td> <asp:Label ID="AccountNameLabel" AssociatedControlID="SearchAccount" > Account Name:</asp:Label> <asp:TextBox ID="SearchAccount" ></asp:TextBox><br /> <asp:Label ID="SearchAccountMessage" ForeColor="red" /> </td> </tr> </table> </asp:WizardStep>
對精靈步驟加入程式碼。您可以處理 Wizard 控制項的 NextButtonClick 事件,以執行程式碼。CurrentStepIndex 屬性值會指出步驟索引編號 (第一個步驟從 0 開始) 所引發之 NextButtonClick 事件的其他精靈步驟。
下列程式碼範例會顯示 NextButtonClick 事件的處理常式,這個處理常式會使用在精靈步驟 (來自先前的程式碼範例) 的 TextBox 控制項中輸入的使用者名稱,並驗證使用者名稱不是空白並且目前不在成員資格資料庫中。您需要將 OnNextButtonClick 屬性加入至頁面上的 CreateUserWizard 控制項,這個頁面會參考 NextButtonClick 事件處理常式的處理常式 (例如,OnNextButtonClick="CreateUserWizard1_NextButtonClick")。
Private Function UserExists(ByVal username As String) As Boolean If Membership.GetUser(username) IsNot Nothing Then Return True Return False End Function Protected Sub CreateUserWizard1_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs) If e.CurrentStepIndex = 0 Then If SearchAccount.Text.Trim() = "" OrElse UserExists(SearchAccount.Text) Then SearchAccountMessage.Text = "That account already exists. Please select an different account name." e.Cancel = True Else Dim userName As TextBox = _ CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox) userName.Text = SearchAccount.Text SearchAccountMessage.Text = "" e.Cancel = False End If End If End Sub
private bool UserExists(string username) { if (Membership.GetUser(username) != null) { return true; } return false; } protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) { if (e.CurrentStepIndex == 0) { if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text)) { SearchAccountMessage.Text = "That account already exists. Please select an different account name."; e.Cancel = true; } else { TextBox userName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); userName.Text = SearchAccount.Text; SearchAccountMessage.Text = ""; e.Cancel = false; } } }
安全性注意事項: 這個控制項有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。ASP.NET Web 網頁預設會驗證使用者輸入,以確保輸入中未包含 HTML 項目或指令碼。如需詳細資訊,請參閱指令碼攻擊概觀。
範例
下列程式碼範例會顯示使用範本的 CreateUserWizard 控制項,這些範本主要是對兩個基礎步驟所定義:CreateUserStep 和 CompleteStep,並且會在 CreateUserStep 之前加入其他精靈步驟。
安全性注意事項: |
---|
此控制項具有接受使用者輸入的文字方塊,而這是一項可能的安全性威脅。在 Web 網頁中的使用者輸入可能會含有惡意的用戶端指令碼。ASP.NET Web 網頁預設會驗證使用者輸入,以確保輸入中未包含 HTML 項目或指令碼。一旦啟用了驗證,就不需要明確檢查使用者輸入中的指令碼或 HTML 項目。如需詳細資訊,請參閱指令碼攻擊概觀。 |
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script >
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
' Determine the checkbox values.
Dim subscribeCheckBox As CheckBox = _
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox"), CheckBox)
Dim shareInfoCheckBox As CheckBox = _
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox"), CheckBox)
Dim userNameTextBox As TextBox = _
CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
Dim user As MembershipUser = Membership.GetUser(userNameTextBox.Text)
User.Comment = "Subscribe=" & subscribeCheckBox.Checked.ToString() & "&" & _
"ShareInfo=" & shareInfoCheckBox.Checked.ToString()
Membership.UpdateUser(user)
' Show or hide the labels based on the checkbox values.
Dim subscribeLabel As Label = _
CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel"), Label)
Dim shareInfoLabel As Label = _
CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel"), Label)
subscribeLabel.Visible = subscribeCheckBox.Checked
shareInfoLabel.Visible = shareInfoCheckBox.Checked
End Sub
Private Function UserExists(ByVal username As String) As Boolean
If Membership.GetUser(username) IsNot Nothing Then Return True
Return False
End Function
Protected Sub CreateUserWizard1_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
If e.CurrentStepIndex = 0 Then
If SearchAccount.Text.Trim() = "" OrElse UserExists(SearchAccount.Text) Then
SearchAccountMessage.Text = "That account already exists. Please select an different account name."
e.Cancel = True
Else
Dim userName As TextBox = _
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)
userName.Text = SearchAccount.Text
SearchAccountMessage.Text = ""
e.Cancel = False
End If
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" >
<title>Untitled Page</title>
</head>
<body>
<form id="form1" >
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" BackColor="#F7F6F3" BorderColor="#E6E2D8"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
OnNextButtonClick="CreateUserWizard1_NextButtonClick"
OnCreatedUser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/Default.aspx">
<WizardSteps>
<asp:WizardStep ID="CreateUserWizardStep0" >
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
Select an Account Name</td>
</tr>
<tr>
<td>
<asp:Label ID="AccountNameLabel" AssociatedControlID="SearchAccount" >
Account Name:</asp:Label>
<asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
<asp:Label ID="SearchAccountMessage" ForeColor="red" />
</td>
</tr>
</table>
</asp:WizardStep>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana">
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" AssociatedControlID="UserName">
User Name:</asp:Label></td>
<td>
<asp:TextBox ID="UserName" ></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" AssociatedControlID="Password">
Password:</asp:Label></td>
<td>
<asp:TextBox ID="Password" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" AssociatedControlID="ConfirmPassword">
Confirm Password:</asp:Label></td>
<td>
<asp:TextBox ID="ConfirmPassword" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" AssociatedControlID="Email">
E-mail:</asp:Label></td>
<td>
<asp:TextBox ID="Email" ></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email"
ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" AssociatedControlID="Question">
Security Question:</asp:Label></td>
<td>
<asp:TextBox ID="Question" ></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" ControlToValidate="Question"
ErrorMessage="Security question is required." ToolTip="Security question is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" AssociatedControlID="Answer">
Security Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" ></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" ControlToValidate="Answer"
ErrorMessage="Security answer is required." ToolTip="Security answer is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="ErrorMessage" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<asp:CheckBox ID="SubscribeCheckBox" Checked="True" Text="Send me a monthly newsletter." />
<br />
<asp:CheckBox ID="ShareInfoCheckBox" Checked="True" Text="Share my information with partner sites." />
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" >
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
Complete</td>
</tr>
<tr>
<td>
Your account has been successfully created.<br />
<br />
<asp:Label ID="SubscribeLabel" Text="You have elected to receive our monthly newsletter."></asp:Label><br />
<br />
<asp:Label ID="ShareInfoLabel" Text="You have elected to share your information with partner sites."></asp:Label></td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="ContinueButton" BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
<NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" HorizontalAlign="Center" />
<CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<StepStyle BorderWidth="0px" />
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script >
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
// Determine the checkbox values.
CheckBox subscribeCheckBox =
(CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox");
CheckBox shareInfoCheckBox =
(CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox");
TextBox userNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
MembershipUser user = Membership.GetUser(userNameTextBox.Text);
user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" +
"ShareInfo=" + shareInfoCheckBox.Checked.ToString();
Membership.UpdateUser(user);
// Show or hide the labels based on the checkbox values.
Label subscribeLabel =
(Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel");
Label shareInfoLabel =
(Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel");
subscribeLabel.Visible = subscribeCheckBox.Checked;
shareInfoLabel.Visible = shareInfoCheckBox.Checked;
}
private bool UserExists(string username)
{
if (Membership.GetUser(username) != null) { return true; }
return false;
}
protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
if (e.CurrentStepIndex == 0)
{
if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text))
{
SearchAccountMessage.Text = "That account already exists. Please select an different account name.";
e.Cancel = true;
}
else
{
TextBox userName =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
userName.Text = SearchAccount.Text;
SearchAccountMessage.Text = "";
e.Cancel = false;
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" >
<title>Untitled Page</title>
</head>
<body>
<form id="form1" >
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" BackColor="#F7F6F3" BorderColor="#E6E2D8"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
OnNextButtonClick="CreateUserWizard1_NextButtonClick"
OnCreatedUser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/Default.aspx">
<WizardSteps>
<asp:WizardStep ID="CreateUserWizardStep0" >
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
Select an Account Name</td>
</tr>
<tr>
<td>
<asp:Label ID="AccountNameLabel" AssociatedControlID="SearchAccount" >
Account Name:</asp:Label>
<asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
<asp:Label ID="SearchAccountMessage" ForeColor="red" />
</td>
</tr>
</table>
</asp:WizardStep>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana">
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" AssociatedControlID="UserName">
User Name:</asp:Label></td>
<td>
<asp:TextBox ID="UserName" ></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" AssociatedControlID="Password">
Password:</asp:Label></td>
<td>
<asp:TextBox ID="Password" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" AssociatedControlID="ConfirmPassword">
Confirm Password:</asp:Label></td>
<td>
<asp:TextBox ID="ConfirmPassword" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" AssociatedControlID="Email">
E-mail:</asp:Label></td>
<td>
<asp:TextBox ID="Email" ></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email"
ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" AssociatedControlID="Question">
Security Question:</asp:Label></td>
<td>
<asp:TextBox ID="Question" ></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" ControlToValidate="Question"
ErrorMessage="Security question is required." ToolTip="Security question is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" AssociatedControlID="Answer">
Security Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" ></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" ControlToValidate="Answer"
ErrorMessage="Security answer is required." ToolTip="Security answer is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="ErrorMessage" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<asp:CheckBox ID="SubscribeCheckBox" Checked="True" Text="Send me a monthly newsletter." />
<br />
<asp:CheckBox ID="ShareInfoCheckBox" Checked="True" Text="Share my information with partner sites." />
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" >
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
Complete</td>
</tr>
<tr>
<td>
Your account has been successfully created.<br />
<br />
<asp:Label ID="SubscribeLabel" Text="You have elected to receive our monthly newsletter."></asp:Label><br />
<br />
<asp:Label ID="ShareInfoLabel" Text="You have elected to share your information with partner sites."></asp:Label></td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="ContinueButton" BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
<NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" HorizontalAlign="Center" />
<CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<StepStyle BorderWidth="0px" />
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>