locked
Designer issue with a control like container RRS feed

  • Question

  • User1711771052 posted

    I did this simple control, for containing other controls:

    1        [ParseChildren(true, "Content")]
    2        public partial class WebUserControl1 : System.Web.UI.UserControl, INamingContainer
    3        {
    4            private ControlCollection _content;
    5    
    6            public ControlCollection Content
    7            {
    8                get { return _content; }
    9            }
    10   
    11           public WebUserControl1()
    12           {
    13               _content = new ControlCollection(this);
    14           }
    15   
    16           protected void Page_Load(object sender, EventArgs e)
    17           {
    18               foreach (Control elem in _content)
    19               {
    20                   PlaceHolder1.Controls.Add(elem);
    21               }
    22   
    23           }
    24       }
    25   
    
     

    And example of a using:  

    1    <uc1:WebUserControl1 ID="WebUserControl11" runat="server">
    2            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    3            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click"></asp:Button>
    4            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    5        </uc1:WebUserControl1>
    
     

    But when I try to switch in designer mode in Visual Studio I've got an error about "... UserControl does not have a public property named 'Label'"

    What I have to do for resolve this? Please help me! :)

    Thursday, June 12, 2008 7:31 AM

Answers

  • User-1407570774 posted

    Hi there,

    Why are you using UserControl. check following code:  

    1    using System.ComponentModel;
    2 using System.Web.UI;
    3 using System.Web.UI.Design;
    4 using System.Web.UI.WebControls;
    5
    6 namespace WebApplication1
    7 {
    8
    9 [ToolboxData("&lt;{0}:Container runat=\"server\" />"), ParseChildren(false), Designer(typeof(ContainerControlDesigner))]
    10 public class Container : WebControl
    11 {
    12
    13 public Container() : base(HtmlTextWriterTag.Div) { }
    14
    15 }
    16
    17 }
    Hope it helps.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 13, 2008 3:05 AM