Extender控件本身并不对原有控件进行更改,而是进行扩展.可以说是前台固定的js文件加上一些后台生成的一些参数进行配合,来对前台显示的控件进行业务操作.废话不多说.看教程来学习下.
1.定义一个继承自ExtenderControl类的控件扩展类
public class FocusExtender : ExtenderControl2.定义元属性
{
}
TargetControlType指定扩展类型
[TargetControlType(typeof(Control))]3.重写GetScriptReferences和GetScriptDescriptors方法
(1)GetScriptReferences方法用于加载js文件集合
(2)GetScriptDescriptors方法用于添加控件行为描述,不好意思不知道怎么描述,反正就是为控件添加属性,事件等一些东西.
protected override IEnumerable<ScriptReference> GetScriptReferences()
{
ScriptReference reference = new ScriptReference();
reference.Path = ResolveClientUrl("FocusBehavior.js");
return new ScriptReference[] { reference };
} protected override IEnumerable<ScriptDescriptor>
GetScriptDescriptors(Control targetControl)
{
ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor
("Samples.FocusBehavior", targetControl.ClientID);
descriptor.AddProperty("highlightCssClass", this.HighlightCssClass);
descriptor.AddProperty("nohighlightCssClass", this.NoHighlightCssClass);
return new ScriptDescriptor[] { descriptor };
}