Login.LoggingIn Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when a user submits login information, before authentication takes place.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public event LoginCancelEventHandler LoggingIn
/** @event */
public void add_LoggingIn (LoginCancelEventHandler value)

/** @event */
public void remove_LoggingIn (LoginCancelEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The LoggingIn event is raised when a user submits login information but before the user is authenticated on the Web site. Use the LoggingIn event to set up any information that you need before authenticating a user.

You can cancel a login attempt during the LoggingIn event by setting the Cancel property of the CancelEventArgs object to true.

After the LoggingIn event is raised, the Login control raises the Authenticate event and then the LoggedIn event.

For more information about handling events, see Handling and Raising Events.

The following code example uses the LoggingIn event to ensure that the user has entered a well-formed e-mail address in the UserName property. If not, the LoggingIn event cancels the login attempt and displays an error message using the InstructionText property.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<!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 e-mail 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)
    if (!IsValidEmail(Login1.UserName))
        Login1.InstructionText = "You must enter a valid e-mail address.";
        e.Cancel = true;
        Login1.InstructionText = String.Empty;


        <FORM runat="server">
            <asp:Login id="Login1" runat="server" 
                UserNameLabelText="E-mail Address:" 
                UserNameRequiredErrorMessage="E-mail Address.">

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions