Login Constructor

Definition

Creates a new instance of the Login control.

C#
public Login();

Examples

The following code example uses the Login constructor to create a new instance of the Login control and add that instance to the Controls collection of a PlaceHolder control.

ASP.NET (C#)
<%@ 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>

Remarks

The Login constructor creates a new instance of the Login control that can be programmatically inserted into a Web page.

The following table shows the initial property values for a new instance of Login.

Property Initial value
RememberMeSet true
VisibleWhenLoggedIn true
FailureAction true
FailureText "Your login attempt has failed. Please try again."
MembershipProvider "Default"
Orientation Vertical
PasswordLabelText "Password:"
PasswordRequiredErrorMessage "Password."
RememberMeSet false
RememberMeText "Remember me next time."
LoginButtonText "Login"
TextLayout TextOnLeft
TitleText "Login"
UserNameLabelText "User Name:"
UserNameRequiredErrorMessage "User Name."

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also