ASP.Net了Itemplate - 申报方式 [英] ASP.Net ITemplate - ways of declaring

查看:267
本文介绍了ASP.Net了Itemplate - 申报方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们希望在我们的用户控件定义模板,我们宣布我们的用户控件这样一个领域

when we want to define a Template in our user controls we declare a field like this in our user controls

public ITemplate MyTemplate { get; set; }

,以便用户定义的模板内容将被重新presented在MyTemplate的,你可以使用它。

so that the user defined templates contents will be represented in MyTemplate, and you can use it.

和有办法自定义模板,例如:

and there are ways to customize the templates, for example

[TemplateInstanceAttribute(TemplateInstance.Single)]
public ITemplate MyTemplate { get; set; }

上面的例子将使定义单个实例模板( http://www.nikhilk.net/SingleInstanceTemplates。 ASPX )。

我无意间看到单个实例模板来和它的力量吹走。

i accidentally came across single instance templates and blown away by the power of it.

我的问题是什么是所有可能与ITemplates的事情?我们如何定义(使用)他们(更具体地说直通注解)。有没有一个适合ITemplates任何好的文档? (请不要点MSDN)

my question is what are all the things possible with ITemplates?? how do we define(use) them (more specifically thru annotations). is there any good documentation available for ITemplates?? (please dont point to msdn)

推荐答案

它看起来像你正确地声明的模板。要真正用自己的模板填充的内容,你在你的标记声明。例如:

It does look like you're declaring the template properly. To actually populate the contents with your own template, you declare it in your markup. Eg:

<MyControl runat="server" ...>
  <MyTemplate>
   ... any standard ASP.NET controls in here
   <asp:Label runat="server" ID="lblName"/>
  </MyTemplate>
</MyControl>

  public void InstantiateIn(Control container) {
      var lblName = container.FindControl("lblName") as Label;
      lblName.Text = "Blah";// set from your data layer or otherwise
      Button b = new Button();
      b.ID = "B";
      container.Controls.Add(b);
  }

这是你要找的是什么?

Is this what you were looking for?

这篇关于ASP.Net了Itemplate - 申报方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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