可以使用以下方法自定义 PasswordRecovery 控件:
·可以编辑显示的模板并更改控件的用户界面 (UI)。
·可以将 ASP.NET 主题应用到该控件。有关更多信息,请参见 ASP.NET 主题和外观概述。
·可以使用控件的属性(如 QuestionLabelText 或 InstructionTextStyle)修改其外观。
1、将一个 PasswordRecovery 控件添加到页面,如下面的代码示例所示。
<asp:PasswordRecovery ID="PasswordRecovery1" Runat="server">
</asp:PasswordRecovery>
2、您可以通过应用样式自定义 PasswordRecovery 控件的外观。使用属性(如 LabelStyle、HyperLinkStyle 和 TitleTextStyle 属性)可以将所有需要的样式应用到模板。若要自定义 PasswordRecovery 控件的内容,请继续执行下面的步骤以修改 PasswordRecovery 控件所使用的模板。
3、创建一个 UserNameTemplate 模板以指定首次呈现控件时显示的标记和控件,如下面的代码示例所示。
<UserNameTemplate>
<table border="0" cellpadding="1">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Forgot Your Password?</td>
</tr>
<tr>
<td align="center" colspan="2">
Enter your User Name to receive your password.</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></td>
<td>
<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="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</UserNameTemplate>
4、创建一个 QuestionTemplate 模板以指定当控件提示用户回答安全提示问题时显示的标记和控件,如下面的代码示例所示。
<QuestionTemplate>
<table border="0" cellpadding="1">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Identity Confirmation</td>
</tr>
<tr>
<td align="center" colspan="2">
Answer the following question to receive your password.</td>
</tr>
<tr>
<td align="right">
User Name:</td>
<td>
<asp:Literal ID="UserName" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
Question:</td>
<td>
<asp:Literal ID="Question" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</QuestionTemplate>
5、创建一个 SuccessTemplate 模板以指定当用户成功找回密码时显示的标记和控件。下面的代码示例演示已定义 SuccessTemplate 模板的 PasswordRecovery 控件的标记。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html >
<head runat="server">
<title>Password Recovery All Templates Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div title="All Templates Sample">
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
<QuestionTemplate>
<table border="0" cellpadding="1">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Identity Confirmation</td>
</tr>
<tr>
<td align="center" colspan="2">
Answer the following question to receive your password.</td>
</tr>
<tr>
<td align="right">
User Name:</td>
<td>
<asp:Literal ID="UserName" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
Question:</td>
<td>
<asp:Literal ID="Question" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</QuestionTemplate>
<UserNameTemplate>
<table border="0" cellpadding="1">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Forgot Your Password?</td>
</tr>
<tr>
<td align="center" colspan="2">
Enter your User Name to receive your password.</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></td>
<td>
<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="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</UserNameTemplate>
<SuccessTemplate>
<table border="0" cellpadding="1">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td>
Your password has been sent to you.</td>
</tr>
</table>
</td>
</tr>
</table>
</SuccessTemplate>
</asp:PasswordRecovery>
</div>
</form>
</body>
</html>