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

J

Jeremy Chapman

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;
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top