Board index » Web Programming » Reading values of anonymous controls

Reading values of anonymous controls

Web Programming105
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


-
 

Re:Reading values of anonymous controls

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

--

www.openmymind.net/">www.openmymind.net/

www.fuelindustries.com/">www.fuelindustries.com/





<KasperBirch@gmail.com>wrote in message

Quote
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







-