468,754 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,754 developers. It's quick & easy.

TextBoxes created dynamically : How to store data?

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>
Nov 18 '05 #1
3 4826
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" <an*******@dotnet247.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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>
Nov 18 '05 #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" <an*******@dotnet247.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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>
Nov 18 '05 #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!
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Briand | last post: by
reply views Thread by Nathan Sokalski | last post: by
reply views Thread by rvdnieuwenhuizen | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.