"Raymond Du" <rd**@yahoo.comwrote in message
news:Oj*************@TK2MSFTNGP06.phx.gbl...
I need to find a way to place multiple textboxes and other controls
dynamically on a web form, I tried to put a placeholder on a form then
create and add controls dynamically into the place holder. It is not
working, all controls added disappear after the postback.
If you don't want them to dissappear during pstback, you have to create
them again on every postback. Contrary to the properties of existing
controls, which are preserved during postback in the ViewState, the fact
that you created new controls is not preserved at all in the ViewState.
You typically add the controls in the Page_Init event, and you don NOT
use a !Page.IsPostBack, that is, you re-create the controls on every
postback. If you do it this way, the values introduced in the controls
before the PostBack can be read in the Page_Load event, because asp.net
recovers them internally during the LoadViewState and LoadPostbackData
events that occur between Init and Load.
See this article:
http://www.codeproject.com/useritems/lifecycle.asp