asp.net如何从用户注册界面获取用户名和密码然后再登陆

我创建了两个界面:
一个是关于用户登录的
一个是关于用户注册的
现在我要用“注册时填的用户名和密码”登陆第一个界面
具体应该怎样做啊
protected void Button1_Click(object sender, EventArgs e)
{
//获取用户名和密码
string name = txtuser.Text;
string pass = txtpass.Text;
if (this.txtuser.Text.Trim() == "" || this.txtpass.Text.Trim() == "")
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名和密码不能为空')</script>");
return;
}

if (TextBox1.Text != Label5.Text)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('验证码不匹配请重新填写')</script>");
return;
}

if (txtuser.Text == "123" && txtpass.Text == "123")

{
Response.Redirect("Creat.aspx?userName=" + txtpass.Text + "");
}

我使用的是用户名123密码也是123
怎样改啊
我们还没学到连接数据库啊?老师要求用 Session

第1个回答  2011-03-25
if (txtuser.Text == "123" && txtpass.Text == "123")

{
Response.Redirect("Creat.aspx?userName=" + txtpass.Text + "");
}

不能这样写啊 你这样写只有用户123才能登陆的跟注册一点关系都没有。
1、首先在注册页面 点击注册时把用户名和密码 保存在数据库一张表中 如user 有两列 name(用户名)和pwd(密码)
2、在登陆界面判断用户是否存在
sqlconnection conn = new sqlconnection(""); ---连接数据库
conn.open(); --打开数据库
string sql=string.format("select count(*) from user where name='{0}' and pwd='{1}',txtuser.Text,txtpass.Text"); --查询数据库用户名是否存在
sqlcommand cmd = new sqlcommand(sql,conn); --执行SQL语句
int i=(int)cmd.executenonquery(); --返回结果(户名存在i 是>0的)
if(i>0)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登陆成功')</script>");

}

ok 就写在这里 基本上就是这样。
第2个回答  2011-03-25
有就自己换呗
style里 backgroundimage
或者 backgroundimage
相似回答