因为点击第二个按钮时,页面PostBack了,而此时你动态添加的控件没有重新装载。
需要在PostBack时重新添加这些文本框。
我帮你改改,稍候。

解决方案 »

  1.   

    update.aspx 
    <form id="Form1" method="post" runat="server">
    <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
    <asp:label id="Label1" runat="server">Label</asp:label>
    <asp:Button id="Button1" onclick="AddControls"  runat="server" Text="Button"></asp:Button>
    <asp:Button id="Button2" onclick="UpdateClick"  runat="server" Text="Button"></asp:Button>
    </form>
    update.aspx.cs
    public void Page_Load(Object Sender, EventArgs e) 
    {
      //.......
      
      //reload the controls
      if (ViewState["ControlLoaded"] != null)
      {
         for (int i=0; i<=3; i++) 
         { 
         TextBox myTextBox= new TextBox(); 
         myTextBox.ID ="myBox"+i; 
         myTextBox.Text="aaaa"+i; 
         PlaceHolder1.Controls.Add(myTextBox); 
         } 
      }
      
    }public void AddControls(Object Sender, EventArgs e) 

    for (int i=0; i<=3; i++) 

    TextBox myTextBox= new TextBox(); 
    myTextBox.ID ="myBox"+i; 
    myTextBox.Text="aaaa"+i; 
    PlaceHolder1.Controls.Add(myTextBox); 
    } // Set the View State 
    ViewState["ControlLoaded"] = "true";

    public void UpdateClick(Object Sender, EventArgs e) 

    TextBox Box;
    for (int i=0; i<=3; i++) 

      Box=(TextBox)PlaceHolder1.FindControl("myBox"+i);
      Label1.Text +=Box.text;