当"必须"我使用asp.net的CreateChildControls()? [英] When "must" I use asp.net CreateChildControls()?

查看:97
本文介绍了当"必须"我使用asp.net的CreateChildControls()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然它似乎是正确的方式,使服务器控件是构建内部的CreateChildControls调用所有子控件。但因为它是很难知道什么时候会被调用(这是整个点作为PERF optimzation),我看到的大多数我们的开发人员的构建中的OnInit,或的OnLoad。而这部作品的情况下的99%。

While it seems that the "right" way to make a server control is to construct all child controls inside CreateChildControls call. But since it's difficult to know when it will be called (which is the whole point as a perf optimzation), I see most of our devs construct in OnInit, or OnLoad. And this works 99% of the case.

有没有情况下,我们必须使用的CreateChildControls?

Are there cases where we have to use CreateChildControls?

推荐答案

您应该始终在构建你的CreateChildControls子控件。这是生命周期适当的时候进行初始化,并将它们添加到控件树。之一的原因,这是许多倍的方法EnsureChildContols被调用时,如果需要的话,然后调用的CreateChildControls。最佳实践,就去做。

You should ALWAYS construct your child controls in CreateChildControls. This is the proper time in the Lifecycle to initialize and add them to the control tree. One of the reasons for this is that many times the method EnsureChildContols is called, which then calls CreateChildControls if necessary. Best Practice, just do it.

这篇关于当"必须"我使用asp.net的CreateChildControls()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆