This is a migrated thread and some comments may be shown as answers.

Custom ServerControl inherited from RadListbox with requiredfieldvalidator not working

0 Answers 45 Views
Forum suggestions
This is a migrated thread and some comments may be shown as answers.
Vinayak
Top achievements
Rank 1
Vinayak asked on 15 Sep 2011, 12:26 PM
Hi,

I am developing Custom server control(Ex : MyRadListBox) by inheriting from RadListBox. And I need RequiredFieldValidator inside the MyRadListBox class. Means need a RequiredFieldvalidator feature with My Custom server control. But its giving error like "Unable to find control id 'MyListBox1' referenced by the 'ControlToValidate' property of ''.

My Code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI;
 
namespace WebApplication1
{
    public class MyListBox : RadListBox
    {
        RequiredFieldValidator rfv ;
        protected override void CreateChildControls()
        {
            rfv = new RequiredFieldValidator();
            rfv.ControlToValidate = this.ID;
            rfv.ErrorMessage = "This is required";
            rfv.EnableClientScript = true;
            base.Controls.Add(rfv);
            base.CreateChildControls();
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            rfv.RenderControl(writer);
        }
    }
}

But If I inherit from simple ASP Listbox it works fine. Look at below code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI;
 
namespace WebApplication1
{
    public class MyListBox : ListBox
    {
        RequiredFieldValidator rfv ;
        protected override void CreateChildControls()
        {
            rfv = new RequiredFieldValidator();
            rfv.ControlToValidate = this.ID;
            rfv.ErrorMessage = "This is required";
            rfv.EnableClientScript = true;
            base.Controls.Add(rfv);
            base.CreateChildControls();
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            rfv.RenderControl(writer);
        }
    }
}

I am not getting why its not working with RadListBox and why its working with normal asp ListBox control?

Please kindly help me to resolve this problem.

Thanks
Vinayak


No answers yet. Maybe you can help?

Tags
Forum suggestions
Asked by
Vinayak
Top achievements
Rank 1
Share this question
or