Custom control with complex property type (System.Web.UI.Control[])

Discussion in 'ASP .Net Building Controls' started by Jeremy Chapman, Feb 15, 2006.

  1. I've built a control with a property of type System.Web.UI.Control[]. I
    have a custom editor which allows me to add items to this collection at
    design time, and the property has persistance so that it serializes in the
    aspx html correctly. My problem is that when I run my application that
    contains my control, I get the following compilation error:

    Description: An error occurred during the compilation of a resource required
    to service this request. Please review the following specific error details
    and modify your source code appropriately.
    Compiler Error Message: CS1586: Array creation must have array size or array
    initializer

    the aspx html for my control looks like the following, which I think is
    correct:

    <myasp:MyControl id="MyControl1" runat="server" Height="130px"
    Width="200px">
    <ControlList>
    <asp:Button ID="frmMyControlButton0" Text="test1"></asp:Button>
    <asp:HyperLink ID="frmMyHyperLink1">test2</asp:HyperLink>
    </ControlList>
    </myasp:MyControl >


    Also, If I close my aspx page in visual studio and re open it, my control is
    replaced by an "Error creating control" message, and the tool tip says ''
    could not be set on property ControlList. It would seem that my control can
    not deserialize the html back into an object. How can I get this to work?

    Here is the relevant code to my control:

    [DefaultProperty("ControlList"),
    ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
    public class MyControl : System.Web.UI.WebControls.WebControl
    {
    private System.Web.UI.WebControls.WebControl[] pControls_m = null;

    [Category("Appearance"),DefaultValue(""),
    Editor(typeof(ControlListEditor),
    typeof(System.Drawing.Design.UITypeEditor))]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    NotifyParentProperty(true),
    PersistenceMode(PersistenceMode.InnerProperty)]
    public System.Web.UI.Control[] ControlList
    {
    get
    {
    return pControls_m;
    }
    set
    {
    pControls_m = value;
    }
    }
    }
     
    Jeremy Chapman, Feb 15, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Chapman

    Custom Control with a complex property type

    Jeremy Chapman, Feb 14, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,651
    Jeremy Chapman
    Feb 15, 2006
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    763
    Stanimir Stamenkov
    Oct 25, 2005
  3. Replies:
    0
    Views:
    902
  4. Robert Mark Bram
    Replies:
    0
    Views:
    700
    Robert Mark Bram
    Feb 4, 2007
  5. Zarko Gajic

    Custom Attributes (AttributeTargets.Property) and Property Type

    Zarko Gajic, Apr 7, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    441
    Zarko Gajic
    Apr 7, 2005
Loading...

Share This Page