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
 
Ad

Advertisements

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

Top