Partilhar via


Login Construtor

Definição

Cria uma nova instância do controle Login.

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

Exemplos

O exemplo de código a seguir usa o Login construtor para criar uma nova instância do Login controle e adicionar essa instância à Controls coleção de um PlaceHolder controle .

<%@ 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>

Comentários

O Login construtor cria uma nova instância do Login controle que pode ser inserida programaticamente em uma página da Web.

A tabela a seguir mostra os valores de propriedade iniciais para uma nova instância do Login.

Propriedade Valor inicial
RememberMeSet true
VisibleWhenLoggedIn true
FailureAction true
FailureText "Sua tentativa de logon falhou. Tente novamente.”
MembershipProvider "Padrão"
Orientation Vertical
PasswordLabelText "Senha:"
PasswordRequiredErrorMessage "Senha".
RememberMeSet false
RememberMeText "Lembre-se de mim da próxima vez."
LoginButtonText "Login"
TextLayout TextOnLeft
TitleText "Login"
UserNameLabelText "Nome de usuário:"
UserNameRequiredErrorMessage "Nome de usuário".

Aplica-se a

Confira também