Partager via


Login Constructeur

Définition

Crée une instance du contrôle Login.

public:
 Login();
public Login ();
Public Sub New ()

Exemples

L’exemple de code suivant utilise le Login constructeur pour créer une instance du Login contrôle et ajouter cette instance à la Controls collection d’un PlaceHolder contrôle.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.ComponentModel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
bool IsValidEmail(string strIn)
{
    // Return true if strIn is in valid email format.
    return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); 
}

void OnLoggingIn(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
    Login loginControl = (Login)PlaceHolder1.FindControl("loginControl");

    if (!IsValidEmail(loginControl.UserName))
    {
        loginControl.InstructionText = "You must enter a valid email address.";
        e.Cancel = true;
    }
    else
    {
        loginControl.InstructionText = String.Empty;
    }
}

void Page_Load(object sender, EventArgs e) 
{
    Login loginControl = new Login();

    loginControl.ID = "loginControl";

    loginControl.HelpPageText = "Help logging in...";
    loginControl.HelpPageUrl = "help.aspx";

    loginControl.PasswordRecoveryText = "Forgot your password?";
    loginControl.PasswordRecoveryUrl = "getPass.aspx";

    loginControl.LoggingIn += new LoginCancelEventHandler(OnLoggingIn);

    PlaceHolder1.Controls.Add(loginControl);

}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </form>
    </body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.ComponentModel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function IsValidEmail(ByVal strIn As String) As Boolean
    ' Return true if strIn is in valid email format.
    Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
End Function

Sub OnLoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)

    Dim loginControl As Login

    loginControl = CType(PlaceHolder1.FindControl("loginControl"), Login)

    If Not IsValidEmail(loginControl.UserName) Then
        loginControl.InstructionText = "You must enter a valid email address."
        e.Cancel = True
    Else
        loginControl.InstructionText = String.Empty
    End If
End Sub

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim loginControl As New Login

    loginControl.ID = "loginControl"

    loginControl.HelpPageText = "Help loggin in..."
    loginControl.HelpPageUrl = "help.aspx"

    loginControl.PasswordRecoveryText = "Forgot your password?"
    loginControl.PasswordRecoveryUrl = "getPass.aspx"

    AddHandler loginControl.LoggingIn, AddressOf OnLoggingIn

    PlaceHolder1.Controls.Add(loginControl)

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </form>
    </body>
</html>

Remarques

Le Login constructeur crée une nouvelle instance du Login contrôle qui peut être insérée par programme dans une page Web.

Le tableau suivant montre les valeurs de propriété initiales d’une nouvelle instance de Login.

Propriété Valeur initiale
RememberMeSet true
VisibleWhenLoggedIn true
FailureAction true
FailureText « Votre tentative de connexion a échoué. Réessayez. »
MembershipProvider « Par défaut »
Orientation Vertical
PasswordLabelText « Mot de passe : »
PasswordRequiredErrorMessage « Mot de passe ».
RememberMeSet false
RememberMeText « Souvenez-vous de moi la prochaine fois. »
LoginButtonText « Connexion »
TextLayout TextOnLeft
TitleText « Connexion »
UserNameLabelText « Nom d’utilisateur : »
UserNameRequiredErrorMessage « Nom d’utilisateur ».

S’applique à

Voir aussi