Reading values of anonymous controls

K

KasperBirch

Hi NG

Im trying to read the values of a bunch of TextBox'es that I add in a
loop, dynamically. The page has an <asp:Table id="table" ...> control,
and I add rows with textboxes like this (from memory, never mind
syntax):


for (int i = 0; i<10; i++)
{
TableRow tr = new TableRow();
TableCell cell = new TableCell();
Textbox text = new TextBox();
Cell.Controls.Add(text);
tr.Cells.Add(cell);
table.Rows.Add(tr);
}

The page also has a button and when the user press it, I would like to
read the values of the textboxes...

If they were declared like "<asp:Textbox ..." I would read them like
"this.TextBox1.Value", but how do I do it when they are anonymous?

Kind regards
- Kasper
 
K

Karl Seguin [MVP]

Dynamically added controls need to be re-added , on or before page_load for
their values to get re-associated with them.

So you'll need to re-do that for loop.

As an alternative, you could give ur textboxes a unique "name" and simply
use Request.Form

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top