开发者

What is the correct ASP.NET Control event/method in which to add nested controls?

What is the correct event开发者_运维技巧/method in the ASP.NET life cycle to dynamically add Child Controls ?

My objective is to ensure that all the input controls on a User Control have the correct associated Validator and Label controls, based on configuration from an external file.

It seems like the correct place should be either OnInit(EventArgs e) or CreateChildControls(). Both of them are behaving a little bit unexpected, and rather than try to debug each of them, I figured I'd first ask you guys which one (or other) to use.


Its OnInit, and you need to do it on first load and on post back.


Since this is a Web User Control (ASCX) create the dynamic controls during OnInit. By creating them during OnInit they will be created on the first page load and on every postback.

The CreateChildControls method is typically used for rendering in custom server controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜