views:

44

answers:

2

I am adding controls dynamically in my webpage. I add them in onload method. everything is working fine..

But I m a bit confused about how it works.. I have read in so many articles that all controls get their values from viewstate before load event. Then how my dynamically added controls get their values when i am adding them in OnLoad event ie after LoadPostData event.

+1  A: 

Load them in Page_Init()

Review the page lifecycle for more info:

http://msdn.microsoft.com/en-us/library/ms178472.aspx

This is a helpful article as well:

http://www.code-magazine.com/article.aspx?quickid=0305101&page=2

David Stratton
A: 

In a typical GET request, the controls are created at Page_Init. Since these dynamic controls are not part of page markup, so in POST BACK, you need to recreate. Be sure that when recreating, it must have same ID otherwise your events/values will not preserve.

Adeel