You can customize the PasswordRecovery control completely, by using templates for every view:
– The UserNameTemplate contains all the controls displayed for the first step of the password recovery process when the user is required to enter the user name.
– The control of the password question step which is placed in the Question template.
– As a last step a Success Template that consists of the controls displayed for the confirmation, which are shown after the password has been sent successfully to the user.
Every template has certain required controls. For example:
– the UserNameTemplate requires a text box for entering the user name
– the QuestionTemplate requires a text box for entering the question
– the SuccessTemplate requires a Literal control for displaying the final confirmation message
A template PasswordRecovery control might look like this:
<asp:PasswordRecovery ID=”PasswordTemplateCtrl” runat=”server”>
<MailDefinition From=”myemail@mydomain.com”
Priority=”high”
Subject=”Important information” />
<UserNameTemplate>
<div align=”center”>
<font face=”Arial Narrow”>
<h2>Forgotten your Password?</h2>
Please enter your user name:<br />
<asp:TextBox ID=”UserName” runat=”server” /> <br />
<asp:Button ID=”SubmitButton” CommandName=”Submit” runat=”server” Text=”Next” /> <br />
<span style=”color: Red”>
<asp:Literal ID=”FailureText” runat=”server” />
</span>
</font>
</div>
</UserNameTemplate>
<QuestionTemplate>
<div align=”center”>
<font face=”Arial Narrow”>
<h2>Forgotten your Password?</h2>
Hello <asp:Literal ID=”UserName” runat=”server” />! <br />
Please answer your password-question:<br />
<asp:Literal ID=”Question” runat=”server” /><br />
<asp:TextBox ID=”Answer” runat=”server” /><br />
<asp:Button ID=”SubmitButton” CommandName=”Submit” runat=”Server” Text=”Send Answer” /><br />
<asp:Literal ID=”FailureText” runat=”server” />
</font>
</div>
</QuestionTemplate>
<SuccessTemplate>
Your password has been sent to your email address
<asp:Label ID=”EmailLabel” runat=”server” />!
</SuccessTemplate>
</asp:PasswordRecovery>
If you use controls with the appropriate ID values and use the appropriate CommandName values for buttons, you don’t have to write any code for the control to work. The next table lists the controls for PasswordRecovery templates:
Additional Template |
ID |
Control Type |
Required? |
Comments |
UserNameTemplate | UserName | System.Web.UI.Web Controls. | Yes | TextBox |
UserNameTemplate | SubmitButton | All controls that support Command event bubbling. | No | Name must be set to Submit. |
UserNameTemplate | FailureText | System.Web.UI.Web Controls. | No | Literal |
QuestionTemplate | UserName | System.Web.UI.Web Controls. | No | Literal |
QuestionTemplate | Question | System.Web.UI.Web Controls. | No | Literal |
QuestionTemplate | Answer | System.Web.UI.Web Controls. | Yes | TextBox |
QuestionTemplate | SubmitButton | All controls that support Command event bubbling. | No | Name must be set to Submit. |
QuestionTemplate | FailureText | System.Web.UI.Web Controls. | No | Literal |
You can use the controls Button, ImageButton, or LinkButton as submit button, because they support event bubbling and a CommandName property. You have to set CommandName to Submit, otherwise, the command is not recognized by the control. The SuccessTemplate doesn’t require any type of control with any special IDs and you can add any control you want there.It’s just for displaying the confirmation. You can use the FindControl method for finding the control (which is actually a child control of the PasswordRecovery template control) in the appropriate template, as follows:
Protected Sub PasswordTemplateCtrl_SendingMail(sender As Object, e As System.Web.UI.WebControls.MailMessageEventArgs) Handles PasswordTemplateCtrl.SendingMail
Dim Lbl As Label = CType(PasswordTemplateCtrl.SuccessTemplateContainer.FindControl(“EmailLabel”), Label)
Lbl.Text = e.Message.To(0).Address
End Sub
You cannot call the FindControl method directly on the PasswordRecovery control instance, because the PasswordRecovery control includes more than one template. You have to select the appropriate template container (UserNameTemplateContainer, QuestionTemplateContainer, or SuccessTemplateContainer). Afterward, you can work with the control as usual.