2012-01-06 55 views
3

用戶單擊註銷按鈕後,我將它帶到一個重定向頁面,該頁面顯示一條消息,並說「在秒內註銷並重定向」。我正在使用asp.net重定向頁面上的倒計時標籤

Response.AddHeader("REFRESH", "3;URL=Login.aspx"); 

有沒有辦法顯示剩餘的秒數,直到它們被重定向到標籤中?

+0

當單擊註銷按鈕時,您可以簡單地在javascript中啓動一個定時事件,遞減某些變量並將其顯示在任何位置。 – 2012-01-06 14:19:38

回答

0

您需要使用客戶端技術,即, JavaScript的。使用服務器端將需要調用服務器,而不需要這樣簡單的事情。

0

由於您使用的是Microsoft aspx,您可以創建在客戶端的標籤,並提出您的代碼隱藏標籤標識實施AJAX並改變剩餘時間的價值基礎。

0

對我的評論之後,你可以通過下面的代碼實現您的解決方案:

<script type="text/javascript"> 
    var timeLeft = 3; 
    function decrementCounter() { 
     if (timeLeft > 0) { 
      document.all('countDown').innerHTML = "Redirecting in " + timeLeft + "..."; 
      timeLeft--; 
      setTimeout("decrementCounter()", 1000); 
     } 
     else { 
      window.location = "http://www.google.com/" 
     } 
    } 
</script> 

<body> 
    <form> 
    <label id="countDown">3</label> 
     <input type="button" value="Display alert box in 3 seconds" onclick="decrementCounter()" /> 
    </form> 
</body> 
1

例如,

當你點擊退出按鈕,您可以創建動態的一個倒計時的JavaScript

protected void OnLogout(object sender, EventArgs e) 
    { 
     string url = "~/Login.aspx"; 
     string msg = "Logging out and Redirecting in ? "; 
     StringBuilder js = new StringBuilder("<script language=\"javascript\">") 
       .Append("var ts = 3; setInterval(\"redirect()\",1000);") 
       .Append("function redirect(){ if(ts == 0){") 
       .Append("window.location.href=\"" + url + "\"; }else{") 
       .Append("document.body.innerHTML = \"msg \" + (ts--)+\"seconds\";}}") 
       .Append("</script>"); 
     Response.Write(js.ToString()); 
    }