设计状态下控件自动命名,按你设定的名字命名,对绑定数据库最有效
protected override void OnLoad(EventArgs e){
if (DesignMode)
{
base.OnLoad(e);
_componentChangeService = this.Site.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
if (_componentChangeService != null)
{
_ += new ComponentChangedEventHandler(componentChangeService_ComponentChanged);
}
}
}
#region IComponentChangeService
public virtual void componentChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)
{
if (e.Member == null || == null) return;
try
{
#region Location
if (e.Member.Name == "Location" || e.Member.Name == "Name")
{
return;
}
#endregion
#region ChangeName
Control control = as Control;
if (control == null) return;
INameCreationService namingService = this.Site.GetService(typeof(INameCreationService)) as INameCreationService;
if (namingService != null && controlName != control.Name && control.Site != null)
{
int i = 0;
while (!namingService.IsValidName(controlName))
{
controlName = "前缀" + i.ToString();
i++;
}
control.Site.Name = controlName;
return;
}
return;
#endregion
}
catch
{
}
}
#endregion
[[it] 本帖最后由 heyu52 于 2008-4-16 00:07 编辑 [/it]]