Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Custom Control with a complex property type

 
Thread Tools Search this Thread
Old 02-14-2006, 11:08 PM   #1
Default Custom Control with a complex property type


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
  Reply With Quote
Old 02-15-2006, 12:35 AM   #2
Jeremy Chapman
 
Posts: n/a
Default Re: Custom Control with a complex property type
I've solved the first issue by adding the following attribute to my custom
property:

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.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(DesignerSerializat ionVisibility.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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom control dropdownlist - need advice tcstom Software 0 04-18-2008 11:28 AM
Eclipse - Axis2 - Java Webservices Error amanjsingh Software 1 10-09-2007 09:03 AM
Need help on Modelsim VHDL syntax? ASAP:) kaji General Help Related Topics 0 03-14-2007 10:43 PM
Need help on a Modelsim VHDL Syntax? ASAP:) kaji Software 0 03-14-2007 10:43 PM
Need Help on a Modelsim VHDL Syntax....ASAP:) kaji Hardware 0 03-14-2007 10:41 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46