C# 用户控件模板
我一直在关注MSDN 模板工作正常,但我有两个大问题 我无法访问模板中的控件,即使我用这些控件装饰模板C# 用户控件模板,c#,asp.net,user-controls,C#,Asp.net,User Controls,我一直在关注MSDN 模板工作正常,但我有两个大问题 我无法访问模板中的控件,即使我用这些控件装饰模板 [TemplateContainer(typeof(MessageContainer))] [PersistenceMode(PersistenceMode.InnerProperty)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 其次,我得到了一
[TemplateContainer(typeof(MessageContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
其次,我得到了一个非常糟糕的设计时错误:
Error Creating Control - TemplateTest1
Type 'System.Web.UI.UserControl' does not have a public property named 'MessageTemplate'.
现在,我之所以要这样做是因为用户控件很棒而且很简单,所以我想创建一个用户控件来产生这个效果
<div class="FormFiled">
--- here i want the ability to put controls that i want ----
<div class="Wrapper">
</div>
</div>
---在这里,我想要的是能够放置我想要的控件----
所以,如果模板化不起作用,除了模板化,还有其他方法可以实现吗
提前感谢。模板的代码在哪里? 它是否在App_Code文件夹中?它是否属于某个名称空间,而您的页面上没有胶水 例如,我使用以下模板
namespace GUI.Controls
{
public class GvTemplate : ITemplate
在后面的代码中,我必须如下调用它:
colField.ItemTemplate = new GUI.Controls.GvTemplate()
如果您不是动态创建模板,您必须在页面顶部注册控件…感谢回复人,我使用的是网站项目,不,控件不在APP_代码中,它与测试ASPX页面一起位于名为ControlTemplate的普通文件夹中。我完全遵循了文章的建议,没有动态模板,只是文章的复制品。