473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Retrieving Dynamic textbox values

Hi Bytes Experts,

I have a web form that I am dynamically adding textboxes to based on a UI selection. This part is working great, however, I need to retrieve the values from the dynamic Textboxes once the user inputs data and click the submit button to send to a xml file.

What is the best way I can collect the values from each textbox. The textboxes are being added in a placeholder control. Also there is no static number of textboxes that will be added by a user.
Sep 12 '10 #1

✓ answered by Christian Binder

Expand|Select|Wrap|Line Numbers
  1.  
  2. List<TextBox> _textBoxes = new List<TextBox>();
  3.  
  4. public void CreateAndAddNewTextBox () {
  5.   TextBox newTextBox;
  6.   //newTextBox = ... dynamically create TextBox
  7.   //add TextBox to your UI
  8.   _textBoxes.Add(newTextBox); //here we add the newly generated TextBox to our list
  9. }
  10.  
If you want to work with the TextBoxes values, you have to iterate the list to obtain the TextBoxes
Expand|Select|Wrap|Line Numbers
  1.   foreach(TextBox textBox in _textBoxes) {
  2.     string value = textBox.Text;
  3.     //do something with the value
  4.   }
  5.  

4 4840
Christian Binder
218 Expert 100+
Each time you create and add a TextBox, you could store a reference to this TextBox in a List<TextBox>. Then you just have to iterate over the List and collect the value of them.
Sep 13 '10 #2
Thanks for the reply.

Question, can you give a brief code syntax of how I would add this Dynamic textboxes List array. I am new to C#/ ASP.net
Sep 13 '10 #3
Christian Binder
218 Expert 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. List<TextBox> _textBoxes = new List<TextBox>();
  3.  
  4. public void CreateAndAddNewTextBox () {
  5.   TextBox newTextBox;
  6.   //newTextBox = ... dynamically create TextBox
  7.   //add TextBox to your UI
  8.   _textBoxes.Add(newTextBox); //here we add the newly generated TextBox to our list
  9. }
  10.  
If you want to work with the TextBoxes values, you have to iterate the list to obtain the TextBoxes
Expand|Select|Wrap|Line Numbers
  1.   foreach(TextBox textBox in _textBoxes) {
  2.     string value = textBox.Text;
  3.     //do something with the value
  4.   }
  5.  
Sep 13 '10 #4
Thanks Christian Binder. The information was very helpful for my project. When I grow up I want to be as good as you!! :-)
Sep 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
2
by: zoneal | last post by:
Anyone can help me how to do dynamic textbox appearance? need it for matrix data entry, suppose i enter 3 and 4 then the 3x4 textboxes will appear.. thank you very much.
0
by: fernandezr | last post by:
Hi, I've got a user control that is referenced twice on the same page and I'd like to access the textbox values on postback so I can update a database. How can get the values for each instance of...
10
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
2
by: Christina | last post by:
Hello !! I am creating a dynamic textbox and want to validate it using the requiredfieldvalidator. These are the steps which I tried: ==================================================== 1)...
2
by: =?Utf-8?B?TG91aXNhOTk=?= | last post by:
Hello. ive just read some posts on the age old issue of losing dynamic control values on postback. Most people say recreate the controls on the onInit, but i just dont think this serves my purpose....
9
by: kumarrk | last post by:
Hi all, i am using place holder for dynamic textbox and label box, then when i enter the values in textbox then i click the add button and save to database, but i couldnt get the dynamic textbox...
4
by: marisenthil | last post by:
How to access the value of the dynamic textbox by its id? I created more dynamic textbox using the below in loop Dim tb As New TextBox tb.ID = "txt_" + Str$(i) and it assigned unique...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.