if(!Page.IsPostBack)
{
for(int i = 0; i < 3; i ++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i;
this.Panel1.Controls.Add(txt);
}
}
改为
for(int i = 0; i < 3; i ++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i;
this.Panel1.Controls.Add(txt);
}

解决方案 »

  1.   

    你的代码在
    if(!Page.IsPostBack)内
    这里的代码只在页面第一次加载的时候才执行的
    提交后Page.IsPostBack就是true就不执行你写的代码了
      

  2.   

    去掉if(!Page.IsPostBack)
    让页面每次执行时都生成你为什么自动生成或者你把TextBox开始隐藏点按钮时显示出来
      

  3.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    for(int i = 0; i < 3; i ++)
    {
    TextBox txt = new TextBox();
    txt.ID = "txt" + i;
    this.Panel1.Controls.Add(txt);
    }
    }private void Button1_Click(object sender, System.EventArgs e)
    {
    string str = "";
    for(int i = 0; i < 3; i ++)
    {
    TextBox txt = (TextBox)Panel1.FindControl("txt" + i);
    str += "第" + i.ToString() + "个文本框的值为:" + txt.Text + "<br>";
    }
    this.Label1.Text = str;
    }
      

  4.   

    去掉if(!Page.IsPostBack)
    让页面每次执行时都生成你为什么自动生成或者你把TextBox开始隐藏点按钮时显示出来
      

  5.   

    回送后不执行!IsPostBack里的代码
      

  6.   

    <script language="c#" runat="server">
    TextBox txt1=new TextBox();
    TextBox txt2=new TextBox();private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!this.IsPostBack)
    {                
       this.EnsureChildControls();
       txt1.Text="hello";
       this.EnsureChildControls();
       txt2.Text="world";
    }
    }protected override void CreateChildControls()
    {
       pnl1.Controls.Add(txt1);
       pnl1.Controls.Add(txt2);
    }
    </script>
      

  7.   

    if(!Page.IsPostBack)
    {
    for(int i = 0; i < 3; i ++)
    {
    TextBox txt = new TextBox();
    txt.ID = "txt" + i;
    this.Panel1.Controls.Add(txt);
    }
    }
    改为:
    for(int i = 0; i < 3; i ++)
    {
    TextBox txt = new TextBox();
    txt.ID = "txt" + i;
    this.Panel1.Controls.Add(txt);
    }