如何用foreach遍历页面上所有的TextBox,判断他们是否为空?

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 codeangel 的 blog

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>;")
      }
   }
}

本文关键:如何用foreach遍历页面上所有的TextBox,判断他们是否为空?
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top