页面加载登录失败错误消息。 [英] Page loading on login failed error msg.

查看:84
本文介绍了页面加载登录失败错误消息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Web应用程序。每当任何用户尝试使用错误的凭据登录该应用程序时,它应显示警告请输入正确的用户ID和密码。但问题是,页面继续在后端加载,直到用户没有单击消息的确定按钮。我想在显示错误消息后避免页面加载。 PLZ帮助。



我尝试过:



以下是我的代码:

HTML:
< asp:Button ID =btnLoginrunat =serverText =Loginclass =buttonOnClientClick = return validateTextPw()OnClick =btnLogin_Clickformmethod =post/>


C#:

protected void btnLogin_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings) [ MmrtgDBConnString]的ConnectionString)。
con.Open();
SqlCommand cmd = new SqlCommand(select * from MSTR_USER,其中UserId = @ username和UserPassword = @ password,con);
cmd.Parameters.AddWithValue(@ username,txtUserId.Value);
cmd.Parameters.AddWithValue(@ password,txtPsd.Value);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count> 0)
{
Response.Redirect(Login.aspx);
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(),validation,< script language ='javascript'> alert('无效的用户名和密码')< /脚本>中);
}
}

解决方案

显示错误消息后,重定向回登录页面。

I have created a web application. Whenever any user tries to login into that application using wrong credentials, it should show alert" Please enter correct Userid and Password". But the problem is that, the page keeps on loading in the backend until the user does not click the "ok" button of the message. I want to avoid page loading after error message has been displayed. plz help.

What I have tried:

Below are my code:

HTML:
                                <asp:Button ID="btnLogin" runat="server" Text="Login" class="button" OnClientClick="return validateTextPw()" OnClick="btnLogin_Click" formmethod="post" />


C#:

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MmrtgDBConnString"].ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from MSTR_USER where UserId =@username and UserPassword=@password", con);
            cmd.Parameters.AddWithValue("@username", txtUserId.Value);
            cmd.Parameters.AddWithValue("@password", txtPsd.Value);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
               ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
            }
        }

解决方案

After displaying the error message, redirect back to the login page.


这篇关于页面加载登录失败错误消息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆