語言

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 屬性來指示某個事件,例如 LoggingIn 該事件、該 LoggingOut 事件或該 ChangingPassword 事件,是否應該被取消。

適用於

另請參閱