WebForm 登陆test

    <script>
        window.onload = function () {
            document.getElementById("form1").onsubmit = function () {
                var userName = document.getElementById("username").value;
                var passWord = document.getElementById("pwd").value;
                if (userName != "" && passWord != "") {
                    return true;
                } else {
                    alert("用户名和密码不能为空!!!");
                    return false;
                }
            }
        }
</script>

        string UserName = context.Request["username"];
        string PassWord = context.Request["pwd"];
  //连接数据库
            SqlConnection con = new SqlConnection("server=.;database=test;uid=sa;pwd=123321");
            //执行sql语句
             string sql = "select count(*) from users where username=@UserName and pwd= @PassWord";
            //string sql = "select * from users";
            SqlCommand cmd = new SqlCommand(sql,con);
            cmd.Parameters.AddWithValue("@UserName",UserName);
            cmd.Parameters.AddWithValue("@PassWord",PassWord);
            con.Open();
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            con.Close();
            if (i==1)
            {
                context.Response.Write("登录成功!!!");
            }
            else
            {
                context.Response.Write("用户名或密码错误!!");
            }
原文地址:https://www.cnblogs.com/enych/p/8257104.html