页面层加一个Panl Cs层: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Default6 : System.Web.UI.Page ... { protected void Page_Load(object sender, EventArgs e) ...{ //if (!IsPostBack) //{ //Panel1.Controls.Add(new LiteralControl("<" + "TABLE id='MenuTable' runat='server' with='100%' height='500px' border='0' cellpadding='0' cellspacing='0' " + ">"));//表开始 aa(); //} } private void aa() ...{ Panel1.Controls.Add(new LiteralControl("<" + "TABLE id='MenuTable' runat='server' with='100%' height='500px' border='0' cellpadding='0' cellspacing='0' " + ">"));//表开始 for (int i = 0; i < 4; i++) ...{ Panel1.Controls.Add(new LiteralControl("<TR>")); Panel1.Controls.Add(new LiteralControl("<TD>")); Label lbl = new Label(); lbl.ID = i.ToString(); lbl.Text = "班组:"; Panel1.Controls.Add(lbl); Panel1.Controls.Add(new LiteralControl("</TD>")); Panel1.Controls.Add(new LiteralControl("<TD>")); TextBox txt = new TextBox(); txt.ID = "txt" + i.ToString(); Panel1.Controls.Add(txt); Panel1.Controls.Add(new LiteralControl("</TD>")); Panel1.Controls.Add(new LiteralControl("<TD>")); Button btn = new Button(); btn.ID = "btn" + i.ToString(); string name= btn.ID; btn.Text = "保存"; btn.Click += new EventHandler(btnClick); //btn.Attributes.Add(name, "OnClick"); Panel1.Controls.Add(btn); Panel1.Controls.Add(new LiteralControl("</TD>")); Panel1.Controls.Add(new LiteralControl("</TR>")); } Panel1.Controls.Add(new LiteralControl("</TABLE>")); } protected void btnClick(object sender, EventArgs e) ...{ string ap = ((Button)sender).ID; string s = ((TextBox)Panel1.FindControl("txt1")).Text; Response.Write(s); }}