0

hi
i want to generate text boxes dynamically .
when i run the program i will get input in integer in a text box with that input (ex input=5) then 5 text box should be generated in my page how to do it .

2
Contributors
1
Reply
8
Views
2 Years
Discussion Span
Last Post by JorgeM
0

So, I assume that you'll have some type of button or other element that you will click. There needs to be an event handler to allow you to execute some code.

in this block of code, you read the value from your text box and then parse the data to make sure its an integer in your acceptable range of values.

Then setup a loop that will iterate up to the number of times of your input. Then just create the textboxes and add them to your placeholder element.

Something like this...its not tested, just to give you something to start with.

//this conceptual/pseudo code within your loop

TextBox txtBox = new TextBox();
txtBox.ID = "txtBox" + num;  //num could be the current iteration from the loop
placeholderElement.Controls.Add(txtBox);

Go back, do some reading, try some code and come back here with some example code of your own with additional questions.

Edited by JorgeM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.