Super newbie question here. I’m trying to teach myself Web Forms, so I’m experimenting with the runat="server" attribute. So here’s my code:
<p>
Number of items:
<input type="checkbox" name="custom_name_qty" value="25" runat="server" />25
<input type="checkbox" name="custom_name_qty" value="50" runat="server" />50
<input type="checkbox" name="custom_name_qty" value="75" runat="server" />75
<input type="checkbox" name="custom_name_qty" value="100" runat="server" />100
<input type="checkbox" name="custom_name_qty" value="Other" runat="server" />Other
</p>
And here’s what gets generated:
<p>
Number of items:
<input name="ctl01" type="checkbox" value="25" />25
<input name="ctl02" type="checkbox" value="50" />50
<input name="ctl03" type="checkbox" value="75" />75
<input name="ctl04" type="checkbox" value="100" />100
<input name="ctl05" type="checkbox" value="Other" />Other
So, it took my group of checkboxes that had the same name, and gave them separate names. Why is this? Even when I give them separate names (add an integer to the end of each one), they still get renamed.
What am I doing wrong here? How can I get the checkboxes to output the same name? How can I even get the checkboxes to keep the names that I give them? I’d rather work with a name I give than “ctl01”.
You are not doing anything wrong, that’s the default behaviour of asp.net. That is otherwise achieved with
<asp:CheckListBox />control: CheckListBoxThat shows how to add items manually. You can also populate the check list from database
Update
In Asp.Net 4 and above, you are given more control on how control ID are generated (e.g. AutoID, Static, Predictable, Inherit)