Generating controls dynamically can be a little tricky. All ASP.NET
controls must reside in a form control. This is rendered for you
automatically (you can see it in the html markup). When you add a
control to the page, you're actually adding it at the end of the
control tree- outside of all other controls, including the form tag.
What you want to do is add a generic control- like a placeholder- to
the page, and then add your textboxes to the placeholder.
placeholder1.Controls.Add(temp);
THis will esnure you're putting it inside the form tag, and it will
also allow you to specify where they show up on the page (because
they'll appear in the placeholder).
As a general best practice, you should always set the ID property of
the textbox.
Secondly, and this is the trickiest part- when you do a postback, you
must make sure all controls are added back to the page in the Init
event. Otherwise, you'll get all sorts of wierd issues like viewstate
errors, etc. If you add three textboxes to the page, send it to the
client- it has to come back the same way. (And by come back, I mean be
constructed in the same way in the Init event).