添加嵌套控件的正确 ASP.NET 控件事件/方法是什么?
ASP.NET 生命周期中动态添加子控件的正确事件/方法是什么?
我的目标是确保用户控件上的所有输入控件都具有基于外部文件的配置的正确关联的验证器和标签控件。
看起来正确的位置应该是 OnInit(EventArgs e)
或 CreateChildControls()
。他们两个的行为都有点出乎意料,我想我应该先问你们要使用哪一个(或另一个),而不是尝试调试它们。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是 OnInit,您需要在首次加载和回发时执行此操作。
Its OnInit, and you need to do it on first load and on post back.
由于这是一个 Web 用户控件 (ASCX),因此在
OnInit
期间创建动态控件。通过在OnInit
期间创建它们,它们将在第一页加载和每次回发时创建。CreateChildControls
方法通常用于在自定义服务器控件中进行呈现。Since this is a Web User Control (ASCX) create the dynamic controls during
OnInit
. By creating them duringOnInit
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.