TextBoxes created dynamically : How to store data?

Discussion in 'ASP .Net' started by Forconi Boris via .NET 247, Jun 17, 2004.

  1. Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created with text, and in each row, there 's atextBox (with an incremental ID number) in witch the user canenter a number of products. When the user clicks on the "Submit"button, I must know witch row he has selected, AND WITCH NUMBERHE HAS ENTERED in the The TextBox area.

    The problem is that the Table is created dynamically (the userhas clicked on a "search" button to create the Table) so I can'tuse the AutoPostBack of each TextBox, or I lose the entireTable. I thought about using ViewState, but to store data I mustknow when the Text of the TextBox changed. I tried to do thiswith a AddHandler, but the TextChanged Method is never called!!
    I don't know how to solve this problem. Help me !!!

    Here is a part of my code (where numResult is the number of rows):

    Protected TableResult As Table
    Dim numResult As Integer

    '(My TextChanged Function to store info)
    Public Sub TB_Changed(ByVal sender As Object, ByVal e AsEventArgs)
    Dim i As Integer = 0
    While (i < numResult)
    ViewState(Convert.ToString(i)) = sender.Text
    i = i + 1
    End While
    End Sub

    '(A part of the function that fill the Table)
    Public Sub ResultsView(ByVal PRef As String, ByVal PDes AsString)

    Dim compteur As Integer = 0

    Dim r As New TableRow
    Dim c1 As New TableCell
    c1.Text = "Qt?"
    r.Cells.Add(c1)
    TableResult.Rows.Add(r)

    While (compteur < numResult)
    Dim ro As New TableRow
    Dim ce1 As New TableCell
    Dim txtB As New System.Web.UI.WebControls.TextBox
    txtB.ID = Convert.ToString(compteur)
    AddHandler txtB.TextChanged, AddressOf TB_Changed
    ce1.Controls.Add(txtB)
    ro.Cells.Add(ce1)
    compteur = compteur + 1
    End While
    End Sub

    Thank u for responding
    (I hope u'll understand, my English is not really good...)

    --------------------------------
    From: Forconi Boris

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>I/JHNHTdekGGZdBcrf9RWA==</Id>
    Forconi Boris via .NET 247, Jun 17, 2004
    #1
    1. Advertising

  2. Hi,

    I'm doing something very similar right now. Here's how you can do it:

    Dynamically add as many controls as you need to in your table (or panel),
    and assign them an ID that is easily referenced.

    When the user clicks on the submit button, you can find the value of each
    textbox this way (If you know the ID's of the textboxes)

    dim c as control
    dim w as string

    c = table1.findcontrol('TheID')
    w = ctype(c,textbox).text


    Hope this helps,

    Steve




    "Forconi Boris via .NET 247" <> wrote in message
    news:...
    Hi, I'm working on a project in witch I have to list data (products that can
    be selected with a certain quantity) from an XML document, with key words
    entered by the user. A Table is dynamically created with text, and in each
    row, there 's a textBox (with an incremental ID number) in witch the user
    can enter a number of products. When the user clicks on the "Submit" button,
    I must know witch row he has selected, AND WITCH NUMBER HE HAS ENTERED in
    the The TextBox area.

    The problem is that the Table is created dynamically (the user has clicked
    on a "search" button to create the Table) so I can't use the AutoPostBack of
    each TextBox, or I lose the entire Table. I thought about using ViewState,
    but to store data I must know when the Text of the TextBox changed. I tried
    to do this with a AddHandler, but the TextChanged Method is never called!!
    I don't know how to solve this problem. Help me !!!

    Here is a part of my code (where numResult is the number of rows) :

    Protected TableResult As Table
    Dim numResult As Integer

    '(My TextChanged Function to store info)
    Public Sub TB_Changed(ByVal sender As Object, ByVal e As EventArgs)
    Dim i As Integer = 0
    While (i < numResult)
    ViewState(Convert.ToString(i)) = sender.Text
    i = i + 1
    End While
    End Sub

    '(A part of the function that fill the Table)
    Public Sub ResultsView(ByVal PRef As String, ByVal PDes As String)

    Dim compteur As Integer = 0

    Dim r As New TableRow
    Dim c1 As New TableCell
    c1.Text = "Qt?"
    r.Cells.Add(c1)
    TableResult.Rows.Add(r)

    While (compteur < numResult)
    Dim ro As New TableRow
    Dim ce1 As New TableCell
    Dim txtB As New System.Web.UI.WebControls.TextBox
    txtB.ID = Convert.ToString(compteur)
    AddHandler txtB.TextChanged, AddressOf TB_Changed
    ce1.Controls.Add(txtB)
    ro.Cells.Add(ce1)
    compteur = compteur + 1
    End While
    End Sub

    Thank u for responding
    (I hope u'll understand, my English is not really good...)

    --------------------------------
    From: Forconi Boris

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>I/JHNHTdekGGZdBcrf9RWA==</Id>
    Steve Caliendo, Jun 17, 2004
    #2
    1. Advertising

  3. Or you will have the values back in the controls if you recreate them in
    the same order as before.

    Trevor Benedict R
    MCSD

    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Trevor Benedict R, Jun 18, 2004
    #3
    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. SD
    Replies:
    3
    Views:
    442
    =?Utf-8?B?S2V6emE=?=
    Jun 23, 2005
  2. RC
    Replies:
    1
    Views:
    576
    Teemu Keiski
    Jun 7, 2005
  3. Nathan Sokalski

    Problem using dynamically created textboxes

    Nathan Sokalski, Jun 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    379
    Nathan Sokalski
    Jun 17, 2005
  4. msimmons
    Replies:
    0
    Views:
    454
    msimmons
    Jul 16, 2009
  5. YunusEmre

    saving text values of dynamically created textboxes

    YunusEmre, Dec 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    15
    Views:
    241
    YunusEmre
    Jan 3, 2005
Loading...

Share This Page