日期:2014-05-18 浏览次数:20582 次
if (userName.Text == " ")
{
warning.Text = "请输入用户名 ";
}
else if (userPwd_1.Text == " ")
{
warning.Text += "请输入密码 ";
}
else if (userPwd_2.Text != userPwd_1.Text)
{
warning.Text += "密码不一致 ";
}
else
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "constr "].ConnectionString);
conn.Open();
string str = "insert into user(user_name,user_Pwd) values( ' " + userName.Text + " ',
' "+userPwd_1.Text + " ') ";
SqlCommand comm = new SqlCommand(str, conn);
comm.ExecuteNonQuery();
conn.Close();
}
------解决方案--------------------
IF在判断的时候思想错了拉 ....
不管你怎么样 !!肯定都会执行button事件的
LS的正解
------解决方案--------------------
用检验控件
<asp:RequiredFieldValidator id="user_t" ControlToValidate="userName" Display="Dynamic" text="必须输入用户名!"
ErrorMessage="必须输入用户名!" runat="server" />
<asp:RequiredFieldValidator id="user_t" ControlToValidate="userPwd_1" Display="Dynamic" text="必须输入密码!"
ErrorMessage="必须输入密码!" runat="server" />
<asp:CompareValidator ControlToValidate="userPwd_2" id="userPwd_1" ControlToCompare="txtpass" Display="Dynamic" Text="两次密码输入不一致" ErrorMessage="两次密码输入不一致!" Operator="Equal" runat="server"/>
</td>
If IsValid
{
write db
}
------解决方案--------------------
在添加的时候验证一下不就行了吗...验证通过了才添加,没有通过就不添加
------解决方案--------------------
最好可以写个js文件名为validate.js
Validator = {