Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:49:12+00:00 2026-05-26T16:49:12+00:00

I have created a composite control. There is no build error in it. In

  • 0

I have created a composite control. There is no build error in it.

In the composite control i am using a Entity Framework Object

The problem is that in the design window i get the error message as shown in PIC:

Composite Control Error Image

There is no Error during build and composite control works well.

I just want to remove this error from Design Time window

EDIT:

Its like how i am adding the composite control:

 <tr>
        <td colspan="3">
             <cc1:AdditionalColumnsCustomControl  ID="AdditionalColumnsCustomControl1" runat="server"
         MainCssClass="A" ControlMode="New" TableID="1" AreValidatorsStatic="true"
        CustomControlWrapper="TableWrapper" ValidationGroup="vl" />
        </td>
    </tr>

In this case how i can i code to get rid of this Design surface error.

Composite COntrol SOurce COde:

 public class AddRowCustomControl : CompositeControl
{
    public void Clear()
    {
        Control c = (Control)FindControl(controlID);

        if (c.GetType() == typeof(DropDownList))
        {
            DropDownList dl = c as DropDownList;

            ListItem lsa = dl.SelectedItem;

            lsa.Selected = false;


        }
        else if (c.GetType() == typeof(ListBox))
        {
            ListBox lb = c as ListBox;

            foreach (ListItem ls in lb.Items)
            {
                if (ls.Selected)
                {
                    ls.Selected = false;
                }

            }

        }
        else if (c.GetType() == typeof(RadioButtonList))
        {
            RadioButtonList rl = c as RadioButtonList;

            foreach (ListItem ls in rl.Items)
            {
                if (ls.Selected)
                {
                    ls.Selected = false;
                }

            }

        }
        else if (c.GetType() == typeof(CheckBoxList))
        {
            CheckBoxList cl = c as CheckBoxList;

            foreach (ListItem ls in cl.Items)
            {
                if (ls.Selected)
                {
                    ls.Selected = false;
                }
            }

        }
        else if (c.GetType() == typeof(CheckBox))
        {
            CheckBox chk = c as CheckBox;

            chk.Checked = false;

        }

        else
        {
            TextBox tx = c as TextBox;

            tx.Text = "";

        }

    }

    public void Rebind()
    {
        Control c = (Control)FindControl(controlID);

        fillControl(ref c  , RowID , ColumnID);

    }

    public string SaveControlValuesInDB()
    {
        using (ExtEntities context = new ExtEntities())
        {
            if (RowID != null && ColumnID != null)
            {
                EntityData ed = context.EntityDatas.Where(p => p.ColID == ColumnID && p.RowID == RowID).FirstOrDefault();

                if (ed == null)
                {
                    ed = new EntityData();
                    ed.RowID = Convert.ToInt32(RowID);
                    ed.ColID = ColumnID;
                    ed.ColValue = ControlValue;
                    context.AddToEntityDatas(ed);

                    context.SaveChanges();

                    return "Successfully Added";
                }
                else
                {
                    ed.ColValue = ControlValue;
                    context.SaveChanges();

                    return "Successfully Updated";
                }

            }
            else
            {
                return "Exception Invalid Row ID";
            }

        }


    }

    public int? RowID
    {
        get;
        set;
    }

    public enum Modes
    {
        New = 0,
        Modify = 1,

        ModifyInGrid = 2,

    }

    public Modes? ControlMode
    {
        get;
        set;
    }

    public int ColumnID
    {
        get;
        set;
    }

    public string ValidationGroup
    {
        get;
        set;
    }

    /// <summary>
    /// Specifes the Display mode of the Validators "Static or Dynamic"
    /// </summary>
    public bool? AreValidatorsStatic
    {
        get;
        set;
    }

    /// <summary>
    /// If true, the wrapper will be DIV's else Table
    /// </summary>
    public Wrapper CustomControlWrapper
    {
        get;
        set;
    }

    public enum Wrapper
    {
        DivWrapper = 0,
        TableWrapper = 1,

    }

    /// <summary>
    /// Css Class Name for Custom Control
    /// </summary>
    public string MainCssClass
    {
        get;
        set;
    }

    /// <summary>
    /// Css Class Name for Custom Control Label
    /// </summary>
    public string LabelCssClass
    {
        get;
        set;
    }

    /// <summary>
    /// Css Class Name for Custom Control's Main Control 
    /// </summary>
    public string ControlCssClass
    {
        get;
        set;
    }

    /// <summary>
    /// Css Class Name for Custom Control's Validators
    /// </summary>
    public string ValidatorCssClass
    {
        get;
        set;
    }

    protected override void OnLoad(EventArgs e)
    {
        if (AreValidatorsStatic == null)
        {
            AreValidatorsStatic = false;
        }

        if (CustomControlWrapper == null)
        {
            CustomControlWrapper = Wrapper.DivWrapper;
        }

        if (string.IsNullOrEmpty(MainCssClass))
        {
            MainCssClass = "CustomControlMainClass";
        }
        if (string.IsNullOrEmpty(ControlCssClass))
        {
            ControlCssClass = "ControlCssClass";
        }
        if (string.IsNullOrEmpty(LabelCssClass))
        {
            LabelCssClass = "LabelCssClass";
        }
        if (string.IsNullOrEmpty(ValidatorCssClass))
        {
            ValidatorCssClass = "ValidatorCssClass";
        }

        if (ControlMode == null)
        {
            ControlMode = Modes.New;
        }

        base.OnLoad(e);

    }


    string controlID = "ControlID";

    public string ControlValue
    {
        get
        {
            Control c = (Control)FindControl(controlID);

            StringBuilder sb = new StringBuilder();

            if (c.GetType() == typeof(DropDownList))
            {
                DropDownList dl = c as DropDownList;

                sb.Append(dl.Text);

                return sb.ToString();
            }
            else if (c.GetType() == typeof(ListBox))
            {
                ListBox lb = c as ListBox;
                foreach (ListItem item in lb.Items)
                {
                    if (item.Selected)
                    {
                        sb.Append(item.Text + "`");
                    }
                }
                return sb.ToString().TrimEnd('`');
            }
            else if (c.GetType() == typeof(RadioButtonList))
            {
                RadioButtonList rl = c as RadioButtonList;

                sb.Append(rl.SelectedItem.Value);
                return sb.ToString();


            }
            else if (c.GetType() == typeof(CheckBoxList))
            {
                CheckBoxList cl = c as CheckBoxList;

                foreach (ListItem li in cl.Items)
                {
                    if (li.Selected == true)
                    {
                        sb.Append(li.Text + "`");
                    }
                }

                return sb.ToString().TrimEnd('`');

            }
            else if (c.GetType() == typeof(CheckBox))
            {
                CheckBox chk = c as CheckBox;

                return chk.Checked ? "TRUE" : "";
            }

            else
            {
                TextBox tx = c as TextBox;
                return tx.Text;
            }

        }

    }

    private void AddOptions(string[] options, ref Control c)
    {
        if (c.GetType() == typeof(DropDownList))
        {
            DropDownList dl = c as DropDownList;
            foreach (string item in options)
            {
                dl.Items.Add(item);
            }

            c = dl;
        }
        else if (c.GetType() == typeof(ListBox))
        {
            ListBox lb = c as ListBox;
            foreach (string item in options)
            {
                lb.Items.Add(item);
            }

            c = lb;
        }
        else if (c.GetType() == typeof(RadioButtonList))
        {
            RadioButtonList rl = c as RadioButtonList;
            foreach (string item in options)
            {
                rl.Items.Add(item);
            }

            c = rl;
        }
        else if (c.GetType() == typeof(CheckBoxList))
        {
            CheckBoxList cl = c as CheckBoxList;
            foreach (string item in options)
            {
                cl.Items.Add(item);
            }

            c = cl;
        }

    }

    protected override void CreateChildControls()
    {

        string ts = MainCssClass;

        using (ExtEntities context = new ExtEntities())
        {
            EntityAttribute _Attribute = context.EntityAttributes.Where(p => p.ID == ColumnID).FirstOrDefault();

            if (_Attribute != null)
            {
                Panel pnl = new Panel();

                string[] _options = null;

                if (_Attribute.ControlOptions != null)
                {
                    _options = _Attribute.ControlOptions.Split('`');
                }
                Label lt = new Label();
                lt.ID = "LabelID";
                lt.Text = _Attribute.ColumnLabel;

                Control c = null;

                int? MaxLength = _Attribute.MaxLength;

                bool Invalidate_Validator = false;

                switch (_Attribute.AttributeTypeID)
                {
                    case 1:
                        TextBox sl = new TextBox();
                        if (_Attribute.MaxLength != null)
                            sl.MaxLength = Convert.ToInt32(_Attribute.MaxLength);
                        c = sl;
                        break;
                    case 2:
                        TextBox ml = new TextBox();
                        ml.TextMode = TextBoxMode.MultiLine;
                        if (_Attribute.MaxLength != null)
                            ml.MaxLength = Convert.ToInt32(_Attribute.MaxLength);
                        c = ml;
                        break;
                    case 3:
                        DropDownList dl = new DropDownList();
                        c = dl;
                        break;
                    case 4:
                        ListBox lb = new ListBox();
                        lb.SelectionMode = ListSelectionMode.Multiple;
                        c = lb;
                        break;
                    case 5:
                        TextBox p = new TextBox();
                        p.TextMode = TextBoxMode.Password;
                        if (_Attribute.MaxLength != null)
                            p.MaxLength = Convert.ToInt32(_Attribute.MaxLength);
                        c = p;
                        break;
                    case 6:
                        CheckBox ck = new CheckBox();
                        Invalidate_Validator = true;
                        ck.Text = _options != null ? _options[0] : "N/A";
                        c = ck;
                        break;
                    //case 7:
                    //    RadioButton rb = new RadioButton();
                    //    rb.Text = _options != null ? _options[0] : "N/A";
                    //    c = rb;
                    //    break;
                    case 8:
                        RadioButtonList rb_list = new RadioButtonList();
                        c = rb_list;
                        break;
                    case 9:
                        CheckBoxList ck_list = new CheckBoxList();
                        Invalidate_Validator = true;
                        c = ck_list;
                        break;
                    default:
                        break;
                }

                RequiredFieldValidator req = null;

                RegularExpressionValidator regx = null;

                AddOptions(_options, ref c);

                c.ID = controlID;

                if (!Invalidate_Validator)
                {
                    if (_Attribute.Mandatory)
                    {
                        req = new RequiredFieldValidator();

                        req.ControlToValidate = c.ID;
                        req.ErrorMessage = _Attribute.ValidationMessage;
                        req.Text = "*";
                        req.Display = AreValidatorsStatic == true ? ValidatorDisplay.Static : ValidatorDisplay.Dynamic;
                        req.ValidationGroup = ValidationGroup;
                    }

                    if (_Attribute.RegularExpressionValue != null)
                    {
                        regx = new RegularExpressionValidator();

                        regx.ControlToValidate = c.ID;
                        regx.ErrorMessage = _Attribute.ValidationMessage;
                        regx.Text = "*";
                        regx.ValidationGroup = ValidationGroup;
                        regx.ValidationExpression = _Attribute.RegularExpressionValue;
                        regx.Display = AreValidatorsStatic == true ? ValidatorDisplay.Static : ValidatorDisplay.Dynamic;

                    }
                }


                if (ControlMode == Modes.Modify)
                {
                    fillControl(ref c, RowID, ColumnID);
                }


                if (CustomControlWrapper == Wrapper.DivWrapper)
                {
                    pnl.Controls.Add(new LiteralControl(@"<div class=""" + MainCssClass + @"""><div class=""" + LabelCssClass + @""">"));

                    if (ControlMode != Modes.ModifyInGrid)
                        pnl.Controls.Add(lt);

                    pnl.Controls.Add(new LiteralControl(@"</div><div class=""" + ControlCssClass + @""">"));
                    pnl.Controls.Add(c);
                    pnl.Controls.Add(new LiteralControl(@"</div><div class=""" + ValidatorCssClass + @""">"));

                    if (req != null)
                        pnl.Controls.Add(req);
                    if (regx != null)
                        pnl.Controls.Add(regx);

                    pnl.Controls.Add(new LiteralControl(@"</div>"));

                    pnl.Controls.Add(new LiteralControl(@"</div>"));

                }
                else
                {
                    pnl.Controls.Add(new LiteralControl(@"<table class=""" + MainCssClass + @"""><tr><td class=""" + LabelCssClass + @""">"));

                    if (ControlMode != Modes.ModifyInGrid)
                        pnl.Controls.Add(lt);

                    pnl.Controls.Add(new LiteralControl(@"</td><td class=""" + ControlCssClass + @""">"));
                    pnl.Controls.Add(c);
                    pnl.Controls.Add(new LiteralControl(@"</td><td class=""" + ValidatorCssClass + @""">"));

                    if (req != null)
                        pnl.Controls.Add(req);
                    if (regx != null)
                        pnl.Controls.Add(regx);

                    pnl.Controls.Add(new LiteralControl(@"</td></tr>"));

                    pnl.Controls.Add(new LiteralControl(@"</table>"));

                }


                Controls.Add(pnl);

            }


        }
    }

    private void fillControl(ref Control c, int? RowID, int ColumnID)
    {
        using (ExtEntities context = new ExtEntities())
        {
            EntityData obj = context.EntityDatas.Where(p => p.RowID == RowID && p.ColID == ColumnID).FirstOrDefault();

            if (obj != null)
            {

                string[] values = obj.ColValue.Split('`');

                string value = obj.ColValue;

                if (c.GetType() == typeof(DropDownList))
                {
                    DropDownList dl = c as DropDownList;

                    dl.Items.FindByText(value).Selected = true;

                }
                else if (c.GetType() == typeof(ListBox))
                {
                    ListBox lb = c as ListBox;

                    foreach (var item in values)
                    {
                        lb.Items.FindByText(value).Selected = true;
                    }

                }
                else if (c.GetType() == typeof(RadioButtonList))
                {
                    RadioButtonList rl = c as RadioButtonList;

                    foreach (var item in values)
                    {
                        rl.Items.FindByText(item).Selected = true;
                    }

                }
                else if (c.GetType() == typeof(CheckBoxList))
                {
                    CheckBoxList cl = c as CheckBoxList;

                    foreach (var item in values)
                    {
                        cl.Items.FindByText(value).Selected = true;
                    }


                }
                else if (c.GetType() == typeof(CheckBox))
                {
                    CheckBox chk = c as CheckBox;

                    chk.Checked = value == "TRUE" ? true : false;

                }

                else
                {
                    TextBox tx = c as TextBox;

                    tx.Text = value;

                }
            }
        }

    }

Thanks

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:49:13+00:00Added an answer on May 26, 2026 at 4:49 pm

    This is due to the fact that at design time the EF objects won’t be available/instantiated. Can verify whether your control is currently be displayed on a design surface with the DesignMode property (MSDN doc):

    if(this.DesignMode == false)
    {
       //do normal instantiations of objects etc.
    }
    else
    {
       //do work related to creating a design time view of your control
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom composite control that contains a text box, some validators, as
I have created a custom server control that inherits from CompositeControl. In the CreateChildControls
I have a custom server control (composite control having dynamically created dropdown boxes and
I have created a custom widget in gwt which extends the composite.I am using
I have a custom button control created using ATL. This control is used by
I have created a composite control with sample details as follows. Basically, the first
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.