O
Oleg Ogurok
Hi all,
In my custom control, I have a property derived from BaseCollection. At
design time, the property shows as (Collection[...]) in the Properties
window, so I can click [...] button and add items to it. The items get shown
as inner XML tags. (An example of what I'm trying to do is DropDownList's
Items property)
The problem is when I switch to HTML (XML) mode and manually change one of
the attributes of my control (or add another item), and then switch back to
the Design mode, I get "Error Creating Control. "" could not be set on
property Nodes."
Something is telling me I have to somehow tell VS.NET to parse the inner XML
back, create a brand new collection and then pass it to the control class
for rendering. The code works fine at runtime but not at design time.
Any ideas? Here's the code:
[DefaultProperty("Nodes"),
ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>"),
ParseChildren(true), PersistChildren(false)]
public class MyControl : System.Web.UI.WebControls.WebControl
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)]
public NodeCollection Nodes
{
get
{ return nodes;
}
set
{ nodes = value;
}
}
The generated HTML (XML) is as follows
<xxx:mycontrol id="mycontrol1" runat="server">
<Nodes>
<xxx:Node Title="Node1"></xxx:Node>
<xxx:Node Title="Node2"></xxx:Node>
</Nodes>
</xxx:mycontrol>
In my custom control, I have a property derived from BaseCollection. At
design time, the property shows as (Collection[...]) in the Properties
window, so I can click [...] button and add items to it. The items get shown
as inner XML tags. (An example of what I'm trying to do is DropDownList's
Items property)
The problem is when I switch to HTML (XML) mode and manually change one of
the attributes of my control (or add another item), and then switch back to
the Design mode, I get "Error Creating Control. "" could not be set on
property Nodes."
Something is telling me I have to somehow tell VS.NET to parse the inner XML
back, create a brand new collection and then pass it to the control class
for rendering. The code works fine at runtime but not at design time.
Any ideas? Here's the code:
[DefaultProperty("Nodes"),
ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>"),
ParseChildren(true), PersistChildren(false)]
public class MyControl : System.Web.UI.WebControls.WebControl
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)]
public NodeCollection Nodes
{
get
{ return nodes;
}
set
{ nodes = value;
}
}
The generated HTML (XML) is as follows
<xxx:mycontrol id="mycontrol1" runat="server">
<Nodes>
<xxx:Node Title="Node1"></xxx:Node>
<xxx:Node Title="Node2"></xxx:Node>
</Nodes>
</xxx:mycontrol>