if (sname.Text == null)
{
Label1.Text = "必填字段为空!";
}
else
{
Label1.Text = "必填字段不为空!";}
不管文本框中有没有值,都显示不为空,为什么??
if (sname.Text == null)
====>
if (sname.Text == "")
文本框的text属性是string类型,将条件改为sname.text==“”
if(string.IsNullOrEmpty(sname.text.trim())
{...
}
else{...
}