日期:2014-05-18 浏览次数:20960 次
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>
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; } } }
------解决方案--------------------
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(); }