If I clicked a button... how can I get the values entered in these dynamic textboxes and then save them into the corresponding field in the database?

int i = 0;

        foreach (var f in selectFields)
        {
            TableRow tr = new TableRow();
            TableCell td1 = new TableCell();
            TextBox txt = new TextBox();
            txt.Text = f.Name;
            txt.ID = "txt" + i.ToString();
            td1.Controls.Add(txt);

            tr.Cells.Add(td1);

            Table1.Rows.Add(tr);

            i++;
        }

    }

Regards,

First you need to create controls dynamically in Page_Load or Page_Init events. Then only the values entered in those controls will be retained between postback. You can get reference of the control using Page.FindControl method. For example,

TextBox txt1 = (TextBox)Page.FindControl("TextBox1");
        string strValue = txt1.Text;

The container controls such as Page, Panel and PlaceHolder etc where you add controls dynamically will have FindControl method which helps to search the naming container for a server control with the specified id parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.