How can I include additional markup within a 'Content' inner property of an ASP.Net WebControl?

与世无争的帅哥 提交于 2019-11-29 11:21:16
Brian Mains

public ITemplate Content

which then you render to the UI like:

Label label = new Label();
this.Content.InstantiateIn(label);

//Render label

EDIT: Make sure the template also defines

[TemplateInstance(TemplateInstance.Single)]

as this allows you to access the controls within the template directly.

You should try to use this:

win_StatusFilter.FindControl("btn_Test") // this will be a Control
win_StatusFilter.FindControl("btn_Test") as Button // this will be a Button if control found, otherwise it will be null.

Otherwise you should define some properties for your control, like in this article: http://msdn.microsoft.com/ru-ru/library/36574bf6%28v=VS.90%29.aspx


Update: According the remarks in this article about ContentTemplate property of the UpdatePanel:

http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.contenttemplate(v=VS.90).aspx

you can get controls from ContentTemplate because of TemplateInstanceAttribute value (UpdatePanel.ContentTemplate has the TemplateInstance.Single).

So you should only use this code:

[PersistenceMode(PersistenceMode.InnerProperty)] 
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 
[TemplateInstance(TemplateInstance.Single)]
public ITemplate Content

More information at:

http://msdn.microsoft.com/ru-ru/library/system.web.ui.templateinstanceattribute(v=VS.90).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!