Javascript在此代码中不起作用

时间:2013-06-08 07:11:44

标签: c# asp.net

当我尝试执行此操作时,不加载警报消息,立即导航到homeNew.aspx页面。但是当重定向代码不可用时,警报消息正确弹出...我需要这两个功能,这意味着单击“确定”后的警报消息它应该被重定向到下一页..请帮助我克服这个问题

if (TextBox2.Text == nic)
{
    Response.Write(@"<script language='javascript'>alert('Check your email to retrieve your user name and password!')</script>");
    Response.Redirect("homeNew.aspx");
    connection.Close();
}
else
{
    Response.Write(@"<script language='javascript'>alert('INVALID Email address and NIC combination, Try Again!')</script>");
}

2 个答案:

答案 0 :(得分:1)

“因为重定向,您编码的java脚本不是由浏览器运行的。 您可以在javascript中编写重定向代码。

if (TextBox2.Text == nic)
{
    Response.Write(@"<script language='javascript'>alert('Check your email to retrive your user name and password!'); window.location=""/homeNew.aspx""</script>");
}
else
{
    Response.Write(@"<script language='javascript'>alert('INVALID Email address and NIC combination, Try Again!')</script>");
}

答案 1 :(得分:0)

alert('Check your email to retrive your user name and password!');
window.location = '/homeNew.aspx';

您需要在脚本标记内执行这两项操作。