In reality, are server controls rarely added programmatically to aspx pages?
I mean, it's easy to add a Button programmactically to an aspx page, but a server con开发者_如何学运维trol's event handler probably has to be set early in the page life cycle (maybe before Control.Load event). As a result in reality, are dynamic controls rarely added to apsx pages?
I wish there is a way to call postback at the server, so that a event is never too late.
If you add the controls in the PreInit or Init events, there are no problems. I dynamically add controls to my webforms pages all the time.
Best thing to do would be read Truly Understanding ViewState and Truly Understanding Dynamic Controls -- you really can't start to do anything really hinky in webforms without that knowledge.
精彩评论