다음을 통해 공유


LoginCancelEventArgs.Cancel 속성

정의

이벤트를 취소해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Cancel { bool get(); void set(bool value); };
public bool Cancel { get; set; }
member this.Cancel : bool with get, set
Public Property Cancel As Boolean

속성 값

true이벤트를 취소해야 하는 경우 그렇지 않으면 . false

예제

다음 코드 예제에서는 이벤트를 사용 하 여 LoggingIn 사용자가 속성에 올바른 형식의 전자 메일 주소를 UserName 입력 했는지 확인 합니다. 그렇지 않은 LoggingIn 경우 이벤트 처리기는 속성을 설정 Cancel 하며 true오류 메시지가 표시됩니다. 예제를 실행하는 데 사용할 수 있는 .aspx 파일은 항목을 참조하세요 LoginCancelEventArgs .

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

설명

Cancel 속성을 사용하여 이벤트, LoggingOut 이벤트 또는 ChangingPassword 이벤트와 같은 LoggingIn 이벤트를 취소할지 여부를 나타낼 수 있습니다.

적용 대상

추가 정보