Override name generator ?
-
How to override the controls's name generator? I have to create a UserControl that is so similiar as the ASP.NET radiobutton, and also I have to use GroupName in order to group the controls. But there is a problem. Because the userControl is inherited from INamingContainer, and because of that even i set the same GroupName for all my UserControls, the Name property of userControls of the groups are all still different. For example And also, i can't set all the usercontrols have to same ID. So how can i solve this problem ?
-
How to override the controls's name generator? I have to create a UserControl that is so similiar as the ASP.NET radiobutton, and also I have to use GroupName in order to group the controls. But there is a problem. Because the userControl is inherited from INamingContainer, and because of that even i set the same GroupName for all my UserControls, the Name property of userControls of the groups are all still different. For example And also, i can't set all the usercontrols have to same ID. So how can i solve this problem ?
Hi there, Because your control implements the the
INamingContainer
interface, so all the child controls are guaranteed that they have unique names and also naming conflicts are avoided on a page. For example, you happen to put another radio button control on the page with the name"RepairType"
, so there is a naming conflict between this radio button and the one in your control if it does not implement theINamingContainer
. For more information, you can se INamingContainer [^] interface. In this case, you can use the html radio markup<input type='radio' name='RepairType'>
instead of the radiobutton control to make sure that at the client side they all have the same name, and at the server side you can retrieve the value of the radio button using theRequets.Form
.