2011-02-11 45 views
1

我有看似簡單的問題,並且在設計正確的解決方案時遇到困難。asp.net登錄 - 如何與信息提示inturrupt?

我有一個正常的asp.net登錄控制。當用戶登錄(併成功通過驗證),我想顯示一個類似的JavaScript消息提示:

警告:這是一個政府系統...等

有100萬和一個方法來做到這一點...但我真的想保持在我的登錄用戶控制。我玩了下面的方法,沒有運氣:

protected void OnAuthenticate(object sender, AuthenticateEventArgs e) 
{ 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "warning", "alert('hello');", true); 
} 

protected void OnLoggingIn(object sender, LoginCancelEventArgs e) 
{ 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "warning", "alert('hello');", true); 
} 

protected void OnLoggedIn(object sender, EventArgs e) 
{ 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "warning", "alert('hello');", true); 
} 

看起來回傳頁面生命週期似乎是在擰我。

也許我應該考慮這個不同?

登錄頁面 - >(成功) - >警告消息頁面 - >用戶信息中心頁

任何意見將不勝感激。

謝謝!

-Josh

編輯:我也試着Page.ClientScript.RegisterClientScriptBlock( 「......」);

+2

你是否在通過調用`Response.Redirect()`登錄後重定向用戶?這會導致任何註冊的JavaScript不被髮射。 – 2011-02-11 02:34:13

回答

1

您正在使用母版頁/基本頁和會話嗎?你可以這樣來做,這樣會第一個非登錄頁面上顯示的警告:

protected void Page_load(object sender, EventArgs e) 
{ 
    if (Request.IsAuthenticated && !Page.IsPostBack())  
     if (session["warningShown"] == null or session["warningShown"] == false) 
     { 
     session["warningShown"] = true; 
     Page.ClientScript.RegisterStartupScript(this.GetType(), "warning", "alert('hello');", true); 

     } 
    } 
} 
0

如果它有助於我用來做這樣的事情與傳統的ASP在當天回...

我的Javascript符合以下條件:

if (confirm('Yes or no')) 
    { 
    return true; 
    } 

這是用Response.write語句寫入頁面的。如果用戶點擊確定,他們會被重定向;如果他們點擊取消,他們會留在頁面上。 (我承認這已經有一段時間了,因爲我已經做了這個,所以這可能不是確切的語法)

這可能不是你正在尋找的,但它可能讓你朝着正確的方向前進。