本实验主要对 PasswordRecovery 控件进行自定义修改。
可以使用以下方法自定义 PasswordRecovery 控件: 可以编辑显示的模板并更改控件的用户界面 (UI)。 可以将 ASP.NET 主题应用到该控件。 可以使用控件的属性(如 QuestionLabelText 或 InstructionTextStyle)修改其外观。 该主题描述如何使用模板自定义 System.Web.UI.WebControls.PasswordRecovery 控件。
若要自定义 PasswordRecovery 控件的内容,请继续执行下面的步骤以修改 PasswordRecovery 控件所使用的模板。
3、创建一个UserNameTemplate 模板以指定首次呈现控件时显示的标记和控件,如下面的代码示例所示。
<UserNameTemplate> <table border="0" cellpadding="1" cellspacing="0" style="border-collapse:collapse;"> <tr> <td> <table border="0" cellpadding="0"> <tr> <td align="center" colspan="2">是否忘记了您的密码?</td> </tr> <tr> <td align="center" colspan="2">要接收您的密码,请输入您的用户名。</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label> </td> <td> <asp:TextBox ID="UserName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="必须填写“用户名”。" ToolTip="必须填写“用户名”。" 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="提交" ValidationGroup="PasswordRecovery1" /> </td> </tr> </table> </td> </tr> </table> </UserNameTemplate>PS:①EnableViewState属性
EnableViewState属性系统默认的值为true。当设置为true时,在传递状态值时就包括该控件;如果设置为false,则传递状态值时则不包括它。既然状态值不包括该控件,则客户端对它进行的操作,服务器端是不响应的。
②AutoPostBack 属性
Autopostback是一种机制(自动根据Web控件的一些事件,将页面自动发回服务器。在一些Web控件中,称为auto post back属性。如果设置为true ,当此控件的某事件发生时,将发送一个request到服务器。
③PasswordRecovery::UserNameTemplate 属性 获取或设置用来显示的用户名视图的模板 PasswordRecovery 控件。 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 alingn="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>PS: ①PasswordRecovery.UserNameTemplate 属性 获取或设置用来显示的用户名视图的模板 PasswordRecovery 控件。 ②CommandName属性 Button控件的CommandName属性相当于ID属性,只是一个作用标识,提示出单击按钮所要进行的操作。通过它的CommandName属性来调用相对应的操作。 5、创建一个 SuccessTemplate 模板以指定当用户成功找回密码时显示的标记和控件。 下面的代码示例演示已定义 SuccessTemplate 模板的 PasswordRecovery 控件的标记。 <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>PS: ①PasswordRecovery.SuccessTemplate 属性 获取或设置用来显示成功视图的模板 PasswordRecovery 控件。 PasswordRecovery类