protected void Page_PreInit(object sender, EventArgs e) { List keys = Request.Form.AllKeys.Where(key => key.Contains("txtDynamic")).ToList(); int i = 1; foreach (string key in keys) { this.CreateTextBox("txtDynamic" + i); i++; } } protected void AddTextBox(object sender, EventArgs e) { int index = pnlTextBoxes.Controls.OfType<TextBox>().ToList().Count + 1; this.CreateTextBox("txtDynamic" + index); } private void CreateTextBox(string id) { TextBox txt = new TextBox(); txt.ID = id; pnlTextBoxes.Controls.Add(txt); Literal lt = new Literal(); lt.Text = "<br />"; pnlTextBoxes.Controls.Add(lt); } protected void GetTextBoxValues(object sender, EventArgs e) { string message = ""; foreach (TextBox textBox in pnlTextBoxes.Controls.OfType<TextBox>()) { message += textBox.ID + ": " + textBox.Text + "\\n"; } ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true); }
private void CreateTextBox(string id) { int x = Convert.ToInt32(txtNum.Text); for (int i = 0; i < x; i++) { TextBox txt = new TextBox(); txt.ID = id; pnlTextBoxes.Controls.Add(txt); Literal lt = new Literal(); lt.Text = "<br />"; pnlTextBoxes.Controls.Add(lt); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)