Last post Apr 04, 2010 07:12 PM by momenee
Apr 04, 2010 06:33 PM|momenee|LINK
I have a custom server control inheriting from CompositeControl. It consists of two RadioButtonlist controls that are rendered side by side in an html table. The number of ListItems in each RadioButtonList is not known until runtime. Depending on how
many items each list contains, the RepeatColumns property of each list is set differently. To do this in the handler for the ItemDataBound event I need to get the count of ListItems in each RadioButtonList. How do I expose the Items.Count property of each
internal RadioButtonList as a top-level property? I tried using a getter to return the count but this generates a compile-time error to the effect that the count cannot be assigned to--even though I have not created a setter.
Similarly, in the handler for the Submit event, I need to get the ClientID of each internal RadioButtonList to pass to a method that checks for data changes. How do I expose the ClientID of each component RadioButtonList as a top-level property?
I can of course index the Controls collection of the composite control to access the child control and read its properties--but that defeats the whole point of making a complex, independent custom server control.
Apr 04, 2010 07:12 PM|momenee|LINK
I figured it out. The custom control needs to be marked with the ParseChildren attribute and each property needs to be marked with the following attributes:
Answer found in Shahram Khosravi's book, Professional ASP.NET 2.0 Server Control and Component Development. It could have been more clearly explained but I am grateful nonetheless.