这个textbox的text属性问题一下让我觉得自己根本不会c#了。
废话少说上code:
        textbox1.ID = "textbox1";
        textbox1.AutoPostBack = true;
        test2.Controls.Add(textbox1);        test1.InnerText = textbox1.Text.ToString();
    <label id="test" runat="server"></label>
    <label id="test1" runat="server"></label>
就这个,我的目的是修改textbox中的数据直接在另一个lable中可以反映出来,最后竟然发现textbox里面的值不管我再前台怎么改都是“”,更奇怪的是我用textchanged在更新test1时总是第一次更新会让test1的值为空。求高手指点,这厢拜谢啊~~~

解决方案 »

  1.   

    放置伊特Textbox,AutoPostBack 设置为true,textchanged事件中对test1赋值,测试正常
      

  2.   

    你是不是在生成textbox1的时候,没有加IsPostBack判断
      

  3.   

    textbox1.AutoPostBack = true;这个除掉。
      

  4.   


    protected void Page_Load(object sender, EventArgs e)
            {                createTextBox();
            }
            private void createTextBox()
            {
                TextBox txt = new TextBox();
                txt.ID = "Txt_value";
                txt.AutoPostBack = true;
                txt.TextChanged += new EventHandler(txtchange);
                ph_text.Controls.Add(txt);
            }        private void txtchange(object sender,EventArgs e)
            {
                foreach(Control con in ph_text.Controls)
                {
                    
                    if (con.GetType().Name.Equals("TextBox") && con.ID == "Txt_value")
                    {
                        TextBox txt=(TextBox)con.FindControl("Txt_value");
                        lbl_value.Text = txt.Text;
                    }
                }
            }
      

  5.   

    protected void Page_Load(object sender, EventArgs e)
        {
            TextBox tb = new TextBox();
            tb.ID = "textbox1";
            tb.AutoPostBack = true;
            form1.Controls.Add(tb);
            tb.TextChanged += new EventHandler(tb_TextChanged);
        }
        protected void tb_TextChanged(object sender, EventArgs e)
        {
            Label1.Text = (form1.FindControl("textbox1") as TextBox).Text.ToString();
        }ID需要查找,另外去掉 if (!IsPostBack)
            {
      

  6.   

    经检查,貌似就是应该在TextChanged 处理,而不能直接通过在page_load里面完成相应动作。3Q大家,散分~~~