My spec calls for a drop down OR two calender boxes along side a radio button group to control which is active, so I made this user control:
<asp:RadioButton
GroupName="group1"
ID="DateMacroRadioButton"
runat="server"
Checked="true" />
<uc:DateMacroSelector ID="DateMacroSelector1" runat="server" />
<asp:RadioButton GroupName="group1"
ID="CustomDateRadioButton"
runat="server"
AutoPostBack="true" Text="" />
<uc:DateSelector ID="DateSelector1" runat="server" />
to
<uc:DateSelector ID="DateSelector1" runat="server" />

I’d like enable/disable child controls using groups:
<asp:RadioButton
GroupName="group1"
ID="DateMacroRadioButton"
runat="server"
Checked="true" />
<uc:EnableGroup ID="EnableGroup1" runat="server"
CheckBoxId="DateMacroRadioButton">
<uc:DateMacroSelector ID="DateMacroSelector1" runat="server" />
</uc:EnableGroup>
<asp:RadioButton GroupName="group1"
ID="CustomDateRadioButton"
runat="server"
AutoPostBack="true" Text="" />
<uc:EnableGroup ID="EnableGroup12 runat="server"
CheckBoxId="CustomDateRadioButton">
<uc:DateSelector ID="DateSelector1" runat="server" />
to
<uc:DateSelector ID="DateSelector1" runat="server" />
</uc:EnableGroup>
How might I go about designing the user control that works this way?
You could create a custom control, something like this ought to work (getting the “parsechildren” settings to make it work in the designer is always annoying but I think this is right):
But honestly, it might be just as easy to simply write an extension method or something, e.g.
Then just use any old control to wrap your groups…
and call that code on prerender:
You could make either work recursively pretty easily to handle deeper nested children if desired.
Come to think of it, you could probably just create a control that extends
PlaceHolderand skip the hard part above… if you want to be able to control what object types are allowed in your container, that’s how you do it, but may be overkill.