簡體   English   中英

在重定向到其他頁面ASP.NET之前顯示警報消息

[英]Show alert message before redirecting to other page ASP.NET

我發現了很多示例,但我不知道為什么這些示例對我不起作用。 我嘗試了這些但徒勞。

我也嘗試了以下方法:

String message = "Session Expired! Log In Again.";
ClientScript.RegisterStartupScript(
    this.GetType(),
    Guid.NewGuid().ToString(), 
    string.Format("alert('{0}');window.location.href = 'default.aspx'", 
    message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")), 
    true);

ScriptManager.RegisterStartupScript(
    this, 
    this.GetType(), 
    "redirect", 
    "alert('Session Expired! Log In Again.'); 
    window.location='" + Request.ApplicationPath + "Account/login.aspx';", 
    true);

Response.Write("
<script language='javascript'>
    window.alert('Session Expired');
    window.location='~/Account/Login.aspx';
</script>");

但所有這些都不會重定向到登錄頁面,僅顯示警告消息。

嘗試這個

window.location.href="Account/Login.aspx";

從路徑中刪除〜運算符

嘗試這個

Response.Write("<script language='javascript'>window.alert('Popup message ');window.location='webform.aspx';</script>");

更改位置和消息。

祝您編碼愉快,AK。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM