語言

LoginStatus.OnLoggingOut(LoginCancelEventArgs) 方法

定義

當使用者點擊控制項上的LoggingOut登出連結時,會觸發LoginStatus事件。

protected:
 virtual void OnLoggingOut(System::Web::UI::WebControls::LoginCancelEventArgs ^ e);
protected virtual void OnLoggingOut(System.Web.UI.WebControls.LoginCancelEventArgs e);
abstract member OnLoggingOut : System.Web.UI.WebControls.LoginCancelEventArgs -> unit
override this.OnLoggingOut : System.Web.UI.WebControls.LoginCancelEventArgs -> unit
Protected Overridable Sub OnLoggingOut (e As LoginCancelEventArgs)

參數

e
LoginCancelEventArgs

LoginCancelEventArgs A 包含事件資料。

範例

以下程式碼範例將事件處理程式附加於事件 OnLoggingOut 。 事件處理程序會更新表單上的欄位,然後取消登出嘗試。

<%@ Page Language="C#" AutoEventWireup="True" %>

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

    void LoginStatus1_LoggingOut(Object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
    {
        Message.Text = "LoggingOut event. Don't go away now.";
        e.Cancel = true;
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="FORM1" runat="server">
            <asp:LoginStatus id="LoginStatus1" 
              runat="server" 
              onloggingout="LoginStatus1_LoggingOut">
            </asp:LoginStatus>
            <p></p>
            <asp:Literal id="Message" 
              runat="server" />
        </form>
    </body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

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

  Sub LoginStatus1_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
    Message.Text = "LoggingOut event. Don't go away now."
    e.Cancel = True
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="FORM1" runat="server">
            <asp:LoginStatus id="LoginStatus1" 
              runat="server" 
              onloggingout="LoginStatus1_LoggingOut">
            </asp:LoginStatus>
            <p></p>
            <asp:Literal id="Message" 
              runat="server" />
        </form>
    </body>
</html>

備註

利用事件 LoggingOut 提供額外處理,例如在使用者登出網站前清理每位使用者的資料。 OnLoggingOut活動可以取消,因此你可以讓使用者在離開網站前儲存購物車或資料庫變更等資料。

如需處理事件的詳細資訊,請參閱 處理和引發事件。

此 OnLoggingOut 方法也允許衍生類別在不附加代理的情況下處理事件。 這是在衍生類別中處理事件的首選技術。

給繼承者的注意事項

在導出類別中覆寫 OnLoggingOut(LoginCancelEventArgs) 時,務必呼叫基底類別的方法 OnLoggingOut(LoginCancelEventArgs) ,讓註冊代理接收事件。

適用於

另請參閱