页面上有20个TextBox和File1,根据他们的值进行判断再操作,如下面:
if (this.File1.Value != "" && this.TextBox1.Text != "")
        {
                flashPath = this.File1.PostedFile.FileName;
                flashPath2 = flashPath.Substring(flashPath.LastIndexOf("\\"));
                File.Copy(flashPath, Framework.GlobalModule.ImagePath + @"FlashPhoto" + "\\" + flashPath2, false);
                bbf.SendBuildingPhoto(buildingName, buildingPhoto, type, bid, orders);
        }
~~~~~~
这可是20个啊,大家有什么方法只做一个判断,然后执行相应的操作

解决方案 »

  1.   

    控件名有规律的话,使用findcontrol
      

  2.   

    将TextBox和File1的id属性按一个规律设置(如,递增),然后循环吧.
      

  3.   

    用循环啊。判断是否是textbox.是的话就做那些动作
      

  4.   

    类似这样for(int i=1; i<=20; i++)
    {
      string controlname = "TextBox" + i.ToString();
      TextBox control = (TextBox)this.Controls.FindControl(controlname);  ....  }
      

  5.   

    请编程遍历页面上所有TextBox控件并给它赋值为string.Empty      foreach (System.Windows.Forms.Control control in this.Controls)
          {
    if (control is System.Windows.Forms.TextBox)
    {
        System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
        tb.Text = String.Empty ;
    }
          }
      

  6.   

    this.Controls.是点不出FindControl方法的。
      

  7.   

    不好意思,写错了,是
    TextBox control = (TextBox)this.FindControl(controlname);