我似乎有一个简单的问题,并且在设计正确的解决方案时遇到了困难。
我有一个普通的asp .net登录控件。当用户登录(并成功通过身份验证)时,我希望显示一个JavaScript消息提示符,如下所示:
警告:这是一个政府system...etc
有100万零1种方法可以做到这一点.但是我真的很想把它保存在我的登录用户控件中。我无缘无故地玩了以下方法:
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("....");
发布于 2012-02-06 19:15:18
您正在使用母版页/基页和会话吗?您可以这样做,以便在第一个非登录页面上显示警告:
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);
}
}
}发布于 2012-02-06 19:28:36
如果这对我有帮助的话,我以前用经典的ASP做过这样的事.
我的Javascript的大意是:
if (confirm('Yes or no'))
{
return true;
}这是用Response.write语句写入页面的。如果用户单击OK,它们将被重定向;如果单击cancel,则将停留在页面上。(我承认我已经有一段时间没有这样做了,所以这可能不是确切的语法)
这可能不是你想要的,但它可能会让你朝着正确的方向前进。
https://stackoverflow.com/questions/4965051
复制相似问题