foreach(Control ctl in this.Controls.Controls)
{
if(ctl.GetType().Name=="TextBox")
{
TextBox tb =new TextBox();
tb=(TextBox)this.FindControl(ctl.ID);
if(tb.Text==string.Empty)
{
Response.Write("<scriptalert('" + ctl.ID + "的值为空。');</script");
break;
}
}
}
2.指定formID里TextBox 判断
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)先找出你的Form的ID
protected HtmlForm yourformID;
foreach (object obj in yourformID.Controls)
{
if (obj is TextBox)
{
TextBox tb = (TextBox)obj;
if (tb.Text = string.Empty)
{
Response.Write("<scriptalert('" + tb.ID + "的值为空。');</script;")
}
}
}