如题,报错:不允许使用子控件主要代码如下:private RequiredFieldValidator fieldValiator;
/// <summary>
/// 创建子控件
/// </summary>
protected override void CreateChildControls()
{
     base.CreateChildControls();
     validator = new RequiredFieldValidator();
     validator.ID = this.ID + "_Val";
     .....
     Controls.Add(validator );
}

解决方案 »

  1.   

    我想做一个自定义控件,在 DropDownList控件里增加一个是否允许为空的属性
      

  2.   

    重写父类方法: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=