LoginCancelEventArgs 类

定义

为可取消的事件提供数据。Provides data for a cancelable event.

public ref class LoginCancelEventArgs : EventArgs
public class LoginCancelEventArgs : EventArgs
type LoginCancelEventArgs = class
    inherit EventArgs
Public Class LoginCancelEventArgs
Inherits EventArgs
继承
LoginCancelEventArgs
派生

示例

下面的代码示例使用LoggingIn事件确保用户UserName在属性中输入了格式正确的电子邮件地址。The following code example uses the LoggingIn event to ensure that the user has entered a well-formed email address in the UserName property. 否则, LoggingIn事件处理程序会通过CancelLoginCancelEventArgs对象的属性设置为来true取消登录尝试。然后, 将显示在InstructionText属性中指定的错误消息。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 email 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 email address.";
            e.Cancel = true;
        }
        else
        {
            Login1.InstructionText = String.Empty;
        }
    }
}
Partial Class LoginCancelEventArgsvb_aspx
    Inherits System.Web.UI.Page

    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

    Protected Sub OnLoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
        If Not IsValidEmail(Login1.UserName) Then
            Login1.InstructionText = "You must enter a valid email address."
            e.Cancel = True
        Else
            Login1.InstructionText = String.Empty
        End If
    End Sub

End Class

下面是可用于运行前面的示例的 .aspx 文件。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>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="LoginCancelEventArgs.vb" Inherits="LoginCancelEventArgsvb_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>

注解

当组件要执行可取消的操作 (如登录到网站) 时, 会引发可取消事件。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.

LoginCancelEventArgsCancel提供属性以指示是否应取消事件。The LoginCancelEventArgs class provides the Cancel property to indicate whether the event should be canceled. 对象用于具有可取消操作 (如Login控件、 CreateUserWizard控件和PasswordRecovery控件) 的控件。 LoginCancelEventArgsA LoginCancelEventArgs object is used with controls that have cancelable actions, such as the Login control, the CreateUserWizard control, and the PasswordRecovery control.

构造函数

LoginCancelEventArgs()

初始化 LoginCancelEventArgs 类的新实例,其 Cancel 属性设置为 falseInitializes a new instance of the LoginCancelEventArgs class with the Cancel property set to false.

LoginCancelEventArgs(Boolean)

初始化 LoginCancelEventArgs 类的新实例,其 Cancel 属性设置为指定值。Initializes a new instance of the LoginCancelEventArgs class with the Cancel property set to the specified value.

属性

Cancel

获取或设置指示是否应取消事件的值。Gets or sets a value indicating whether the event should be canceled.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅