当前位置:编程学习 > asp >>

Asp.Nte登陆代码 有急用 我用的是VS2008 是用C#开发的 数据库是Sql Server 2005

答案:protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string name = TextBox1.Text.Trim();
        string pwd = TextBox2.Text.Trim();
        string inputcode = TextBox3.Text.Trim();
        string code = Session["image"].ToString();
        if (name != string.Empty || pwd != string.Empty || inputcode != string.Empty)
        {
            if (inputcode == code)
            {
                string cmd = "select * from tb_login where Name='" + name + "' and Pwd='" + pwd + "'";
                int count = db.ExeSqlCount(cmd);
                if (count > 0)
                {
                    Session["user"] = name;
                    Response.Redirect("main.html");
                }
                else
                {
                    Response.Write("<script>alert('用户名或密码错误!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('验证码错误!')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('输入不能为空!')</script>");
        }
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        TextBox1.Text = string.Empty;
        TextBox2.Text = string.Empty;
        TextBox3.Text = string.Empty;
    }
}

上一个:ASP.NET中,如何在配置文件中添加连接字符串,并在后来的代码中使用?
下一个:asp.net(c#)中如何把用户上传的照片保存到数据库中?代码怎么写?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,