开发者

Is there a better way to access controls in an ITemplate than FindControl()?

When a control is added to an UpdatePanel, it can still be accessed from the code behind of the containing page. How is this achieved? Can custom control developers do the same?

In other words, if I develop a template control using the ITemplate Interface, is there a way to wire it up (开发者_运维问答like the UpdatePanel seems to) so that any controls contained within (declaratively) can be accessed from the containing page also?


You can add a TemplateInstanceAttribute on your ITemplate property to achieve this, it has the effect of promoting the controls to page level:

[TemplateInstance(TemplateInstance.Single)]
public ITemplate AnonymousTemplate {
  get { ... }
  set { ... }
}

From MSDN:

The TemplateInstanceAttribute class allows you to mark a template property as one that allows single or multiple instantiations. A template that only allows a single instantiation can have the controls that are contained inside of it referenced. The ZoneTemplate property is an example of a property that can be instantiated only one time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜