Well, this is just the problem (and the reason to use templates and not apply them on Page_Load time):
1. The markup is being parsed and the initial controls tree is being created
2. The Page_Init handler is called
- there is no viewstate
to apply, so this step doesn't do anything;
3. The Page_Load's handler is called (you add some controls dynamically);
- viewstate is being created
4. The response (the entire rendered page) is sent to the requester
5. On the client event occurs, which is being handled on the server and the page postbacks
-the view state is being sent to the server with this postback, too
6. Repeat 1., 2.
7. Now there is viewstate
so the server attempts to apply it on the controls tree, but the tree is not the same as the one represented in the viewstate
(your dynamically added controls are not going to be recreated up until Page_Load time
) and the viewstate is not being applied correctly.
Actually on this stage you should get the controls added on page_load as they first were, so the problem should be only with persisting state. But since they are disappearing completely, I am pretty sure that you have if-statement somewhere at the beginning:
which makes this adding of the controls only the first time Page_Load handler is called (only when it isn't postback).
There is better place to add you controls (better time actually) and it's in the Page_Init handler - it's before the viewstate is being applied. Also you will have to add them every time, not only the first time (just like the structure from the markup is being read and parsed on every postback).
I recommended using templates, because that's what they are all about - adding controls to the nodes. That is what templating is all about.
Hope my answer will give you a better understanding of the lifecycle of the page, the viewstate and the page controls tree recreation.
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Telerik Public Issue Tracking
system and vote to affect the priority of the items