Reading values of anonymous controls

Discussion in 'ASP .Net' started by KasperBirch@gmail.com, Mar 29, 2006.

  1. Guest

    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
     
    , Mar 29, 2006
    #1
    1. Advertising

  2. 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
    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    <> wrote in message
    news:...
    > 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
    >
     
    Karl Seguin [MVP], Mar 29, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bijoy Naick
    Replies:
    1
    Views:
    318
    Peter O'Reilly
    May 4, 2004
  2. Reporter
    Replies:
    3
    Views:
    477
    Mike Schilling
    May 12, 2007
  3. DaDev

    Reading Values of Datagrid Controls

    DaDev, Jun 24, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    111
    DaDev
    Jun 24, 2004
  4. MaverickAmit

    reading values between custom controls

    MaverickAmit, Oct 2, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    110
    Fredrik Normén NSQUARED2
    Oct 2, 2003
  5. Replies:
    1
    Views:
    223
Loading...

Share This Page