Custom Control with a complex property type

Discussion in 'ASP .Net' started by Jeremy Chapman, Feb 14, 2006.

  1. I have a property will an array of webcontrols.

    The control features a custom property editor which can add and remove web
    controls to the array, but how do I persist the informtion by serializing it
    to the aspx page?

    For example, right now, here is what the html looks like when I drag my
    control on to the page and add some web controls to the ControlList
    property:

    <myasp:MyControl id="MyControl6" runat="server" Height="32px" Width="152px"
    ControlList="WebControl[] Array"></myasp:MyControl>

    What I want is for the ControlList property to serialize something like:

    <myasp:MyControl id="MyControl6" runat="server" Height="32px" Width="152px">
    <ControlList>
    <asp:linkbutton id="LinkButton1"
    runat="server">LinkButton</asp:linkbutton>
    <asp:imagebutton id="ImageButton1" runat="server"></asp:imagebutton>
    <asp:button id="Button1" runat="server" Text="Button"></asp:button>
    <asp:hyperlink id="HyperLink1"
    runat="server">HyperLink</asp:hyperlink>
    <asp:label id="Label1" runat="server">Label</asp:label>
    </ControlList>
    </myasp:MyControl>

    Is this possible?
     
    Jeremy Chapman, Feb 14, 2006
    #1
    1. Advertising

  2. I've solved the first issue by adding the following attribute to my custom
    property:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    NotifyParentProperty(true),
    PersistenceMode(PersistenceMode.InnerProperty)]

    This causes the html in my aspx page to look like:

    <myasp:MyControl id="MyControl1" runat="server" Width="88px" Height="266px">
    <ControlList>
    <asp:Button ID="frmControlButton0"></asp:Button>
    </ControlList>
    </myasp:MyControl>

    But now, if I close my web form and re-open it, Visual studio can't create
    the control on my page, I get an error '' could not be set on property
    ControlList. What does this mean?

    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.WebControls.WebControl[] ControlList
    {
    get
    {
    return pControls_m;
    }
    set
    {
    pControls_m = value;
    }
    }
    }


    "Jeremy Chapman" <please@Idontlikespam> wrote in message
    news:%...
    >I have a property will an array of webcontrols.
    >
    > The control features a custom property editor which can add and remove web
    > controls to the array, but how do I persist the informtion by serializing
    > it to the aspx page?
    >
    > For example, right now, here is what the html looks like when I drag my
    > control on to the page and add some web controls to the ControlList
    > property:
    >
    > <myasp:MyControl id="MyControl6" runat="server" Height="32px"
    > Width="152px" ControlList="WebControl[] Array"></myasp:MyControl>
    >
    > What I want is for the ControlList property to serialize something like:
    >
    > <myasp:MyControl id="MyControl6" runat="server" Height="32px"
    > Width="152px">
    > <ControlList>
    > <asp:linkbutton id="LinkButton1"
    > runat="server">LinkButton</asp:linkbutton>
    > <asp:imagebutton id="ImageButton1"
    > runat="server"></asp:imagebutton>
    > <asp:button id="Button1" runat="server" Text="Button"></asp:button>
    > <asp:hyperlink id="HyperLink1"
    > runat="server">HyperLink</asp:hyperlink>
    > <asp:label id="Label1" runat="server">Label</asp:label>
    > </ControlList>
    > </myasp:MyControl>
    >
    > Is this possible?
    >
     
    Jeremy Chapman, Feb 15, 2006
    #2
    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. Stanimir Stamenkov
    Replies:
    2
    Views:
    750
    Stanimir Stamenkov
    Oct 25, 2005
  2. Robert Mark Bram
    Replies:
    0
    Views:
    687
    Robert Mark Bram
    Feb 4, 2007
  3. Zarko Gajic

    Custom Attributes (AttributeTargets.Property) and Property Type

    Zarko Gajic, Apr 7, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    437
    Zarko Gajic
    Apr 7, 2005
  4. Jeremy Chapman

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

    Jeremy Chapman, Feb 15, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    165
    Jeremy Chapman
    Feb 15, 2006
  5. Replies:
    0
    Views:
    178
Loading...

Share This Page