I have two buttons . One button creates a Textbox and another that transmits information. I am having trouble finding user texts after creating a Textbox . Here is the code:
private void CreateTextBox(int j) //Creates the fields / cells { TextBox t = new TextBox(); t.ID = "Textbox" + j; //t.Text = "Textbox" + j; lstTextBox.Add(t); var c = new TableCell(); c.Controls.Add(t); r.Cells.Add(c); table1.Rows.Add(r); Session["test"] = lstTextBox; } protected void Button2_Click(object sender, EventArgs e) { string[] holder = new string[4]; for (int i = 0; i < holder.Length; i++) { holder[i] = ""; } List<TextBox> lstTextBox = (Session["test"] as List<TextBox>); if (lstTextBox.Count < Counter) { int i = lstTextBox.Count; for (int j = 0; j < i; j++) { holder[j] = lstTextBox[j].Text; } SqlConnection conns = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString1"].ConnectionString); SqlCommand cmd = new SqlCommand("Insert into LoanerForm (field0, field1, field2, field3) Values (@field0, @field1, @field2, @field3)", conns); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@field0", holder[0]); cmd.Parameters.AddWithValue("@field1", holder[1]); cmd.Parameters.AddWithValue("@field2", holder[2]); cmd.Parameters.AddWithValue("@field3", holder[3]); conns.Open(); cmd.ExecuteNonQuery(); conns.Close(); } Counter = 0; Button1.Visible = true; //Going to submit data to SQL }
Thank you in advance!
source share