ASP.NET:Get values of dynamically added controls.

By admin - Last updated: Wednesday, March 5, 2008 - Save & Share - Leave a Comment

At the stage of OnInit, all control objects are performing initialization, if added controls were not initialized at this stage, and even though the postback data contain the values of those controls, you won’t be able to obtain the user inputed values of those controls at later stage. e.g. PageLoad, OnClickHandler method.

In order to retrieve values that entered by users from dynamically added controls, those control objects have to be initialized at OnInit stage. The tricky part at that stage is that you couldn’t get persisted data of previous request from viewstate. The way I did to get around of that is to either modify the control’s postbackUrl which caused postback action to the same page with querystring attaching persisted data. Secondly, you can load the data from the database to generate your dynamic controls at that stage, OnInit.

Once dynamically added controls are initialized at OnInit stage, the postback data including user entered data in the form will fill up those controls at later stage in the pipeline.




Posted in Code Notes • Tags: , , Top Of Page