Insights and discoveries
from deep in the weeds

Wednesday, February 16, 2011

Radio Buttons, Asp.Net, Checked, intellisense fail.

Radio buttons are just a pain in the butt. They shouldn't be, but they are. ASP.NET makes them even more painful, because it doesn't really honor the basic construct in which radio buttons were created. That is, we set a "name" which identifies the group, and then we can look at the one that is "checked" within that group.

If you have radio buttons that you need to deal with on both the server and the client, well, it becomes sort of ridiculous. You are looking for totally different things on the client as you are at the server.

Anyway, in a recent effort to make some sense of a radio button group that I needed to manipulate at the client, I found myself giving up on server controls, and just went back to this:

<input clientidmode="Static" value="0" type="radio" runat="server" name="MyButtonGroup" id="MyButton" checked="true" />

clientidmode="static" will prevent from mucking up the "name" so I can find this group in a useful manner at the client.

Here's the best part.

Intellisense complains about "checked": The values permitted for this attribute do not include "true."

So I change it to "checked" which is the only permitted value.

Now I get a run-time error:

Cannot create an object of type 'System.Boolean' from its string representation 'checked' for the 'Checked' property.

So which way do you want it Microsoft?


No comments:

Post a Comment