繁体   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