【问题标题】:Show alert message before redirecting to other page ASP.NET在重定向到其他页面 ASP.NET 之前显示警报消息
【发布时间】:2018-07-29 10:36:48
【问题描述】:

我找到了很多例子,但我不知道为什么这些对我不起作用。这些我都试过了,但是没用。

我也尝试了以下方法:

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>");

但所有这些都不会重定向到仅显示警报消息的登录页面。

【问题讨论】:

  • 谁能告诉我为什么这一行显示警报消息但没有重定向到登录页面。 ScriptManager.RegisterStartupScript( this, this.GetType(), "redirect", "alert('Session Expired! Log In Again.'); window.location='~" + Request.ApplicationPath + "Account/login.aspx';", true);

标签: javascript c# asp.net


【解决方案1】:

试试这个

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

从路径中移除~操作符

【讨论】:

    【解决方案2】:

    试试这个

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

    更改位置和消息。

    快乐编码 问候, AK。

    【讨论】:

      猜你喜欢
      • 2013-08-20
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      相关资源
      最近更新 更多