次の方法で共有


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 イベントなどのイベントを取り消す必要があるかどうかを示すことができます。

適用対象

こちらもご覧ください