Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding ASP Textbox dynamically
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00817593
Message ID:
00817731
Views:
22
I tried that but does not work. If I just add two or more textboxes programmatically in the code (in Page_load or click method), it works. But if there is a code to add just one textbox, then, on each loop, only one textbox is added. Or it could be that the second textbox is added but is "placed" right at the same space where the first one is. Therefore, I can only see one textbox. Or maybe the next one (after the first) never gets added to the placeholder.

Frustrating, especially since I follow code in an example in ASP.NET Unleashed (the only different is that the author's example is in VB and I use C#). Otherwise, the same. Yet, he even has a picture of how nice each textbox is placed after the other.


>I think you have to use the Page_Load method, so that the added controls are available before the page is rendered.
>
>>No, the code is in the click method of a button that is supposed to add a textbox.
>>
>>>Are you putting the code in the Page_Load() method?
>>>
>>>>I have been struggling with this problem all day yesterday and hope someone might suggest a solution or a web site to where solution might be.
>>>>
>>>>I want to dynamically add a ASP textbox to a Placeholder when user clicks on a button.
>>>>
>>>>The following code:
>>>>
>>>>
>>>>txtTextBox = new TextBox();
>>>>txtTextBox.ID = "txtProduct" + strFieldNum;
>>>>PlaceHolder1.Controls.Add( txtTextBox );
>>>>
>>>>
>>>>creates one textbox (and not ASP textbox). On the next button click, even though the value "strFieldNum" is incrementing, the same textbox just gets refreshed. How can I change the code to make it ASP textbox and to make it add new one every time.
>>>>
>>>>Any suggestions would be greatly appreciated.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform