Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add controls in runtime

Status
Not open for further replies.

murugesanks

Programmer
Jan 25, 2001
48
0
0
US
How to add textboxes in a Button Click
i.e
1. My web form has a Button(ButtonA)
2. Every time, when i click the button(ButtonA), a New Textbox should be created and place in my web form
3. And when i click another button(ButtonB), the values of all the textboxes should be stored in Database

I am new to ASP.NET, Please help me...
 
To add a control to a page, simply create a New instance of it and then add it to the page (or a control that belongs to the page e.g. a placeholder). e.g.
Code:
Dim tb as New TextBox
PlaceHolder1.Controls.Add(tb)
You will have to create each dynamic control each time the page is loaded.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks.
its working fine. But i was unable to change the position of text box. say first text box top position is 100, and second should be 150, third 200..

below is the code
======================
Dim strTextName As String
Dim tb As New TextBox
tb.ID = "txtSample" + i.ToString()
tb.Style("Top") = j.ToString() + "px"
i = i + 1
j = j + 50
PlaceHolder1.Controls.Add(tb)
======================
 
Rather than create inline styles, I'd suggest using a seperate CSS file to position the controls. You can either do this by assigning each TextBox a different CSSClass or you could use the ID of each TextBox and then have a seperate entry in your CSS file for each ID.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top