假设你的这些TextBox都是在一个WinForm界面上,那么: foreach(Control c in this.Controls) { TextBox txtBox = c as TextBox; if(txtBox!=null && txtBox.Text.Trim()=="") { MessageBox.Show("当前文本框没有任何内容!"); txtBox.Focus(); } } 追问: 但是我的是ASP.NET啊 你这个怎么不行啊 回答: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TextBoxes.WebForm1" %>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TextBoxes { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { for (int i = 0; i < 11; i++) { form1.Controls.Add(new TextBox()); } } } } }
希望采纳