Click here to Skip to main content
15,559,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,
I had developed a server control which acts as a container (user can add any control inside the server control).

C#
[DefaultProperty("Text")]
    [Designer(typeof(ContainerControlDesigner))]
    [ParseChildren(false)]
    [ControlBuilderAttribute(typeof(SampleControlBuilder))]
    [ToolboxData("<{0}:Sample  runat="server"></{0}:Sample>")]
    public class Sample: WebControl, INamingContainer
    {
protected override void CreateChildControls()
        {
            System.Collections.IEnumerator myEnumerator = items.GetEnumerator();
            while (myEnumerator.MoveNext())
                this.Controls.Add((TextBox)myEnumerator.Current);
        }

        protected override void AddParsedSubObject(Object obj)
        {
            if (obj is TextBox)
            {
                items.Add(obj);
            }
        }
    }
public class SampleControlBuilder : ControlBuilder
    {
        public override Type GetChildControlType(String tagName,
                                            IDictionary attributes)
        {
            if (String.Compare(tagName, "myitem", true) == 0)
            {
                return typeof(TextBox);
            }
            return null;
        }
    }

    public class SampleContainerControlDesigner : ContainerControlDesigner
    {
        public override bool AllowResize
        {
            get { return false; }
        }

        private Style _style = null;
ublic override string FrameCaption
        {
            get
            {
                return "Dynamic Page Loader";
            }
        }

        public override Style FrameStyle
        {
            get
            {
                if (_style == null)
                {
                    _style = new Style();
                    _style.Font.Name = "Verdana";
                    _style.Font.Size = new FontUnit("XSmall");
                    _style.BackColor = Color.LightBlue;
                    _style.ForeColor = Color.Black;
                }

                return _style;
            }
        }
    }


When the server control droped:

ASP.NET
<cc1:Sample ID="Sample"  runat="server" />


When the user add some control to the server control:

ASP.NET
<cc1:Sample ID="Sample"  runat="server" >
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</cc1:Sample



Now, what I want is to add some controls within the server control tags just after the user had dropped the server control from toolbox into the webform asp.

How can I do this?????

Best regards :)
Posted
Updated 25-Sep-13 18:16pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900