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

前端 未结 2 1041
忘了有多久
忘了有多久 2020-12-19 16:45

I\'ve searched the site and I cannot find a solution for my problem, so apologies if it\'s already been answered (I\'m sure someone must have asked this before).

I h

相关标签:
2条回答
  • 2020-12-19 17:00

    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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题