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

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

    <myasp:MyControl id="MyControl1" runat="server" Height="130px"
    <asp:Button ID="frmMyControlButton0" Text="test1"></asp:Button>
    <asp:HyperLink ID="frmMyHyperLink1">test2</asp:HyperLink>
    </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:

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

    public System.Web.UI.Control[] ControlList
    return pControls_m;
    pControls_m = value;
    Jeremy Chapman, Feb 15, 2006
    1. Advertisements

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.