当前位置:编程学习 > C#/ASP.NET >>

急问:我想封装一个DropDownList控件,创建一个子控件,加一个验证属性

如题,报错:不允许使用子控件

主要代码如下:

private RequiredFieldValidator fieldValiator;
/// <summary>
/// 创建子控件
/// </summary>
protected override void CreateChildControls()
{
     base.CreateChildControls();
     validator = new RequiredFieldValidator();
     validator.ID = this.ID + "_Val";
     .....
     Controls.Add(validator );
} --------------------编程问答-------------------- 自己顶 --------------------编程问答-------------------- 能把问题再说仔细点吗? --------------------编程问答-------------------- 我想做一个自定义控件,在 DropDownList控件里增加一个是否允许为空的属性 --------------------编程问答-------------------- 顶起来 --------------------编程问答-------------------- 重写父类方法:CreateControlCollection()

        protected override System.Web.UI.ControlCollection CreateControlCollection()
        {
            return new ControlCollection(this);

        }


=======================================================================
Quiet easy, huh!? If you have the same problem when inheriting from out-of-the-box control, this will be the fix.
Hope this helps.
Reference: http://www.codeproject.com/KB/aspnet/DoesNotAllowChildControls.aspx

顺便说一句,遇到解决不了的问题,请参考Google,语言选择英文。
http://www.google.com.hk/search?hl=en&source=hp&q=Does+Not+Allow+Child+Controls&meta=&aq=f&aqi=g-m2&aql=&oq=&gs_rfai=
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,