如何用foreach遍历页面上所有的TextBox
程序员文章站
2022-05-18 14:28:15
1.整个页面的判断
foreach(control ctl in this.controls[1].controls){ if(ctl.gettype().name=="textbox")...
1.整个页面的判断
foreach(control ctl in this.controls[1].controls)
{
if(ctl.gettype().name=="textbox")
{
textbox tb =new textbox();
tb=(textbox)this.findcontrol(ctl.id);
if(tb.text==string.empty)
{
response.write("<script>alert(" + ctl.id + "的值为空。);</script>");
break;
}
}
}
2.指定formid里textbox 判断
先找出你的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("<script>alert(" + tb.id + "的值为空。);</script>;")
}
}
}