You need to reference the ClientID of the control; this is the id in the final html.
Of course, another approach might be to use some other attribute (such as the css etc), and use jQuery to find it; jQuery takes a lot of DOM pain away from javascript. It is interesting that jQuery is now even supported by VS2008 (with intellisense etc).
I'm currently reading jQuery in Action, and liking it much. To take an example straight from the book (on the subject of radios):
var x = $('[name=radioGroup]:checked').val();
which returns the value of the single checked radio button in the group, or undefined
if none is selected.
Re getting the name; it uses the internal UniqueGroupName
property, which does a lot of mangling. An option (but not an attractive one) would be to use reflection to read UniqueGroupName
. Alternatively, use something simple like a literal control. Gawd I hate the ASP.NET forms model... roll on MVC...
Fianlly - I'm currently looking at the public VS2010 CTP image; one of the new additions for ASP.NET is static ClientID
s, by setting ClientIdMode = Static on the control. A bit overdue, but not unwelcome.