0

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,

2
Contributors
1
Reply
4
Views
8 Years
Discussion Span
Last Post by Ramesh S
0

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.

Edited by Ramesh S: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.