1.自定义控件中的子控件
控件功能:创建SimpleRotator2和RotatorItem2 子控件,从SimpleRotator2中选择任意一个RotatorItem2 并显示其text值
<%>
using System;
using System.Web;
using System.Web.UI;
using System.Collections;

}
2.自定义控件构建器
在上面例子中每个子控件都需要有Runat="Server",这样显得很麻烦,因为子控件使用的是默认的控件构建器,所以需要这样声明,可以通过更换我们自己的构建器
<%>
using System;
using System.Web;
using System.Web.UI;
using System.Collections;

}
以上代码均没有使用元数据,所以在项目中如果要引入到工具栏中,需要自行编译,然后引用其dll
如果在代码中使用了元数据,则将其引用到项目中时系统会根据元数据自动在工具栏创建这个控件,并从你所定义的元数据中获取其属性
如:
[DefaultPropertyAttribute("CardholderNameText")]
[ToolboxData(@"<{0}:CreditCardForm2
PaymentMethodText='信用卡类型' CreditCardNoText='信用卡卡号'
CardholderNameText='信用卡持有者姓名' SubmitButtonText = '提交'
runat='server'></{0}:CreditCardForm2>")
]
为改控件添加了默认属性
[BrowsableAttribute(true)]
[DescriptionAttribute("获取或设置信用卡卡号")]
[DefaultValueAttribute("信用卡卡号")]
[CategoryAttribute("Appearance")]
为控件属性设定属性
相关文章: