TextBox tx = new TextBox();
        tx.ID = "ID";
        this.PlaceHolder1.Controls.Add(tx);这句代码写了之后每点击一次就只会出来一个TextBox、请问如何实现点击一次出来一个,点击按钮只是一个Button按钮

解决方案 »

  1.   

    把 生成的按钮的ID放到 session里,在page_load中遍历后重新生成试试http://www.mybuffet.cn
      

  2.   

    因为动态生成的东西,每次提交到后台后,会消失的,
    实际上你每次点击button都是新生成了一个textbox的,只是以前生成的不见了
      

  3.   

     
    HtmlTable tabletest= new HtmlTable ();//添加表格
     HtmlTableRow trContent = new HtmlTableRow();//添加tr
     HtmlTableCell tdtxt = new HtmlTableCell(); //添加td
    TextBox txt1 = new TextBox();添加textbox
     txt1.ID = "txt_01";
     txt1.Attributes.Add("onfocus", "this.select();");
     txt1.Text ="abc";
     tdtxt.Controls.Add(txt1);
     trContent.Cells.Add(tdtxt);
     tabletest.Rows.Add(trContent);
      

  4.   


     //2009/12/29 测试通过
        static int i = 0;
        protected void Button1_Click(object sender, EventArgs e)
        {
            for (int j = 0; j <= i; j++)
            {
                TextBox tx = new TextBox();
                tx.ID = "ID" + j.ToString();
                this.PlaceHolder1.Controls.Add(tx);
            }
            i++;
        } 
      

  5.   

    你可以用js加html控件来做啊
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
      <script type="text/javascript">
          var i = 0;
          function aa() {
              i++;
              txt = document.createElement("input");
              txt.type = "text";
              txt.id = "aa" + i;
              txt.setAttribute("onclick", "aa()");
              div1.appendChild(txt);
          }
      </script>
     </head>
    <body id="aaaa">
        <form id="form1" runat="server">
        <div  style=" width:auto; vertical-align:middle;" id="div1">
            <input id="Text1" type="text"  onclick="aa();" />
        </div>
        </form>
    </body>
    </html>
      

  6.   

    这种动态添加TextBox的方法,建议还是在客户端用js做比较好
    然后在服务器端用Request.Form取服务器端进行添加控制,比较麻烦,每次都要记录现在应该创建几个TextBox
      

  7.   

    你可以用Count计点击Button按钮的次数。然后遍历添加就可以了。
      

  8.   

    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 Default28 : System.Web.UI.Page
    {    int i;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               // Session["num"] = i;            i = 0;
                Session["i"] = i;
                Response.Write("第一次:"+Session["i"].ToString());
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
           
           
             int j=Convert.ToInt32(Session["i"])+1;
            Session["i"] =Convert.ToString(j);
            Response.Write(Session["i"].ToString());
            for (int i = 0; i < Convert.ToInt32(Session["i"]); i++)
            {
                
                    TextBox tx = new TextBox();
                    tx.ID = "ID" + i.ToString();
                    this.Form.Controls.Add(tx);
                        }
            }
    }
    我试过了可以。你可以看看;