-1

我有一个 HTML 表单,通过登录将我重定向到 aspx 页面:

<form method="post" action="../login.aspx">

如果数据正确,一切正常,但是当数据失败时,我需要显示错误消息,我该怎么做?

在 aspx 页面中,当一切正常时,我有一个重定向,但是当登录失败时,您尝试发出警报并重定向到我的 html 页面,但这不起作用,用户转到 html 页面但未显示警报:

Response.Redirect("~/Users.aspx"); //here everything is ok
                }
            }
            // if the login is wrong
            else
            {
                Response.Write("<script>alert(the login is wrong);</script>");
                Response.Redirect(Request.UrlReferrer.ToString());
            }
4

3 回答 3

5

如果条件错误,请在 c# 代码中插入以下代码

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Your Alert Message Here');", true);

于 2013-01-14T09:38:57.800 回答
1

像这样尝试你的脚本

Response.Write("<script language='javascript'>alert('the login is wrong');</script>");

希望对你有帮助

于 2013-01-14T10:10:58.300 回答
0

您的问题不清楚,但我认为您正在 asp.net 中寻找表单验证。你可以很容易地从谷歌搜索它。

但这里有一些方便的教程。我最近在处理表单验证时使用过。

http://www.codeguru.com/csharp/.net/net_asp/webforms/article.php/c19353/Form-Validation.htm

http://weblogs.asp.net/dotnetstories/archive/2011/01/13/validation-in-asp-net-applications.aspx

你可以使用它。

希望它会帮助你。

于 2013-01-14T09:35:28.557 回答