写一个验证函数
private bool Is_Exist()
{string Constring = "Provider=SQLOLEDB;Data Source=.;Integrated Security=SSPI;Initial Catalog=shopingdb";
OleDbConnection conn = new OleDbConnection(Constring);
string sql = "select * from users where userName='";
sql += txb_name.Text.Trim() + "'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
txb_name.Text = "";
return true;
}
else
return false;
}
再在button中写代码
protected void LinkButton8_Click(object sender, EventArgs e)
{
if(!Is_Exist())
{
//不存在该用户,可注册
}
else//存在返回
{
}
}
验证控件是在页面执行的,也就是说验证控件生效的话,就不会走到后台了,你可以单步调试看看,程序有没有走到后台