Comment : personnaliser le contrôle PasswordRecovery

Mise à jour : novembre 2007

Il existe plusieurs façons de personnaliser le contrôle PasswordRecovery:

Cette rubrique décrit comment personnaliser le contrôle System.Web.UI.WebControls.PasswordRecovery à l'aide des modèles.

Pour modifier le modèle PasswordRecovery

  1. Ajoutez un contrôle PasswordRecovery à la page comme indiqué dans l'exemple de code suivant.

    <asp:PasswordRecovery ID="PasswordRecovery1" Runat="server">
    </asp:PasswordRecovery>
    
  2. Vous pouvez également appliquer des styles pour personnaliser l'apparence du contrôle PasswordRecovery. Utilisez des propriétés pour appliquer les styles souhaités au modèle, telles que les propriétés LabelStyle, HyperLinkStyle et TitleTextStyle.

    Pour personnaliser le contenu du contrôle PasswordRecovery, continuez avec les étapes suivantes pour modifier les modèles utilisés par le contrôle PasswordRecovery.

  3. Créez un modèle UserNameTemplate pour spécifier le balisage et les contrôles qui apparaissent lorsque le contrôle est restitué en premier, comme indiqué dans l'exemple de code suivant.

    Note de sécurité :

    Cet exemple a une zone de texte qui accepte l'entrée d'utilisateur, ce qui constitue une menace éventuelle pour la sécurité. Par défaut, les pages Web ASP.NET vérifient que les entrées d'utilisateur n'incluent pas de script ou d'éléments HTML. Pour plus d'informations, consultez Vue d'ensemble des attaques de script.

    <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"  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="PasswordRecovery1">*</asp:RequiredFieldValidator>
                </td>
              </tr>
              <tr>
                <td align="center" colspan="2" style="color: red">
                  <asp:Literal ID="FailureText"  EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton"  CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </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"  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="PasswordRecovery1">*</asp:RequiredFieldValidator>
                </td>
              </tr>
              <tr>
                <td align="center" colspan="2" style="color: red">
                  <asp:Literal ID="FailureText"  EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton"  CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </UserNameTemplate>
    
  4. Créez un modèle QuestionTemplate pour spécifier le balisage et les contrôles qui apparaissent lorsque le contrôle invite l'utilisateur à répondre à la question de sécurité, comme indiqué dans l'exemple de code suivant.

    Note de sécurité :

    Cet exemple a une zone de texte qui accepte l'entrée d'utilisateur, ce qui constitue une menace éventuelle pour la sécurité. Par défaut, les pages Web ASP.NET vérifient que les entrées d'utilisateur n'incluent pas de script ou d'éléments HTML. Pour plus d'informations, consultez Vue d'ensemble des attaques de script.

    <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" ></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  Question:</td>
                <td>
                  <asp:Literal ID="Question" ></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">Answer:</asp:Label></td>
                <td>
                  <asp:TextBox ID="Answer" ></asp:TextBox>
                  <asp:RequiredFieldValidator ID="AnswerRequired"  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"  EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton"  CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </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" ></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  Question:</td>
                <td>
                  <asp:Literal ID="Question" ></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">Answer:</asp:Label></td>
                <td>
                  <asp:TextBox ID="Answer" ></asp:TextBox>
                  <asp:RequiredFieldValidator ID="AnswerRequired"  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"  EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton"  CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </QuestionTemplate>
    
  5. Créez un modèle SuccessTemplate pour spécifier le balisage et les contrôles qui apparaissent lorsqu'un utilisateur a récupéré un mot de passe avec succès

    L'exemple de code suivant montre le balisage d'un contrôle PasswordRecovery à l'aide d'un modèle SuccessTemplate défini.

    Note de sécurité :

    Cet exemple a une zone de texte qui accepte l'entrée d'utilisateur, ce qui constitue une menace éventuelle pour la sécurité. Par défaut, les pages Web ASP.NET vérifient que les entrées d'utilisateur n'incluent pas de script ou d'éléments HTML. Pour plus d'informations, consultez Vue d'ensemble des attaques de script.

    <%@ Page Language="VB" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script >
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head >
      <meta http-equiv="Content-Type" content="text/html" />
      <title>PasswordRecovery All Templates Sample</title>
    </head>
    <body>
        <form id="form1" >
        <div title="All Templates Sample">
          <asp:PasswordRecovery ID="PasswordRecovery1" >
            <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" ></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          Question:</td>
                        <td>
                          <asp:Literal ID="Question" ></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">Answer:</asp:Label></td>
                        <td>
                          <asp:TextBox ID="Answer" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="AnswerRequired"  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"  EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton"  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"  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="PasswordRecovery1">*</asp:RequiredFieldValidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2" style="color: red">
                          <asp:Literal ID="FailureText"  EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton"  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>
    
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script >
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head >
        <title>Password Recovery All Templates Sample</title>
    </head>
    <body>
        <form id="form1" >
        <div title="All Templates Sample">
          <asp:PasswordRecovery ID="PasswordRecovery1" >
            <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" ></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          Question:</td>
                        <td>
                          <asp:Literal ID="Question" ></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">Answer:</asp:Label></td>
                        <td>
                          <asp:TextBox ID="Answer" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="AnswerRequired"  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"  EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton"  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"  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="PasswordRecovery1">*</asp:RequiredFieldValidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2" style="color: red">
                          <asp:Literal ID="FailureText"  EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton"  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>
    

Voir aussi

Concepts

Personnalisation de l'apparence des contrôles de connexion ASP.NET

Référence

Vue d'ensemble des contrôles de connexion ASP.NET