as it simplest, you'd implement a collection class (TheControlsItemsCollection) and item class (TheControlsItem) which you'd use in specifying a property for your custom controls. It would be something like:
Public Class TheControlsItemsCollection
Inherits <SomeCollectionBaseClass>
End Class
...
Public Class TheControlsItem
End Class
... 'Property in your control
Private _theControlsItems As TheControlsItemsCollection
<NotifyParentProperty(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerProperty)> _
Public ReadOnly Property TheControlsItems() As TheControlsItemsCollection
Get
If _theControlsItems Is Nothing Then
_theControlsItems = New TheControlsItemsCollection()
End If
Return _theControlsItems
End Get
End Property
...
Now, this doesn't for example have anything state management related and therefore this way this works only if you set these declaratively on aspx, as you a little bit shoed on your post. And if you want it to work so that you can for example set these from
code, and have the state kept over postbacks, you'd need to implement state management for your control and the collection.
terrys999
Member
70 Points
14 Posts
Settings Within a Custom Control
Dec 06, 2005 02:53 PM|LINK
I have succeeded in creating a custom web control, which within the HTML looks something like this...
---------------------------
<cc1:TheControl></cc1:TheControl>
---------------------------
From this...
---------------------------
<ToolboxData("<{0}:TheControl runat=server></{0}:TheControl>")> Public Class TheControl
Inherits System.Web.UI.WebControls.WebControl
'...stuff
End Class
---------------------------
My question is, how do I create items within that control. That is....
---------------------------
<cc1:TheControl>
<TheControlsItems>
<TheControlsItem></TheControlsItem>
</TheControlsItems>
</cc1:TheControl>
---------------------------
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: Settings Within a Custom Control
Dec 06, 2005 06:19 PM|LINK
Hi,
as it simplest, you'd implement a collection class (TheControlsItemsCollection) and item class (TheControlsItem) which you'd use in specifying a property for your custom controls. It would be something like:
Public Class TheControlsItemsCollection
Inherits <SomeCollectionBaseClass>
End Class
...
Public Class TheControlsItem
End Class
... 'Property in your control
Private _theControlsItems As TheControlsItemsCollection
<NotifyParentProperty(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerProperty)> _
Public ReadOnly Property TheControlsItems() As TheControlsItemsCollection
Get
If _theControlsItems Is Nothing Then
_theControlsItems = New TheControlsItemsCollection()
End If
Return _theControlsItems
End Get
End Property
...
Now, this doesn't for example have anything state management related and therefore this way this works only if you set these declaratively on aspx, as you a little bit shoed on your post. And if you want it to work so that you can for example set these from code, and have the state kept over postbacks, you'd need to implement state management for your control and the collection.
Teemu Keiski
Finland, EU
terrys999
Member
70 Points
14 Posts
Re: Settings Within a Custom Control
Dec 08, 2005 03:15 PM|LINK
Thanks, that worked great.
As a sub-question to this, how do you group properties in the property window?
Currently I have...
<Category("Pie Chart Properties")>
which will make all of the properties in with that setting show up under ...
[-] PieChartProperties
-SliceDepth:
-PieAngle
However, I now want to organize these to...
[-] Chart Settings
[-]Pie Specific
-SliceDepth
-PieAngle