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

 


 

相关文章:

  • 2021-11-27
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
  • 2021-06-11
  • 2021-09-23
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案