0

Hi guys,
I had developed a server control which acts as a container (user can add any control inside the server control).

[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:

<cc1:Sample ID="Sample"  runat="server" />

When the user add some control to the server control:

<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 (without user add anything) 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 :)

2
Contributors
1
Reply
27
Views
3 Years
Discussion Span
Last Post by LastMitch
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.