Export (0) Print
Expand All

LoginCancelEventArgs Class

Provides data for a cancelable event.

System.Object
  System.EventArgs
    System.Web.UI.WebControls.LoginCancelEventArgs
      System.Web.UI.WebControls.MailMessageEventArgs

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

public class LoginCancelEventArgs : EventArgs

The LoginCancelEventArgs type exposes the following members.

  NameDescription
Public methodLoginCancelEventArgs()Initializes a new instance of the LoginCancelEventArgs class with the Cancel property set to false.
Public methodLoginCancelEventArgs(Boolean)Initializes a new instance of the LoginCancelEventArgs class with the Cancel property set to the specified value.
Top

  NameDescription
Public propertyCancelGets or sets a value indicating whether the event should be canceled.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

A cancelable event is raised when a component is about to perform an action that can be canceled, such as logging on to a Web site.

The LoginCancelEventArgs class provides the Cancel property to indicate whether the event should be canceled. A LoginCancelEventArgs object is used with controls that have cancelable actions, such as the Login control, the CreateUserWizard control, and the PasswordRecovery control.

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 handler cancels the logon attempt by setting the Cancel property of the LoginCancelEventArgs object to true.Then the error message specified in the InstructionText property is displayed.

public partial class LoginCancelEventArgscs_aspx : System.Web.UI.Page
{

    bool IsValidEmail(string strIn)
    {
        // Return true if strIn is in valid e-mail format. 
        return System.Text.RegularExpressions.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})(\]?)$");
    }

    protected 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;
        }
        else
        {
            Login1.InstructionText = String.Empty;
        }
    }
}

The following is the .aspx file that can be used to run the preceding example.

<%@ Page Language="C#" CodeFile="LoginCancelEventArgs.cs" Inherits="LoginCancelEventArgscs_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="Form1" runat="server">
            <asp:Login id="Login1" 
              runat="server" 
              onloggingin="OnLoggingIn">
            </asp:Login>
        </form>
    </body>
</html>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft