Master pages, radio buttons and JavaScript, oh my!

C

CtrlAltDel

Here's a question for you - how do you reference the name of a radio
button group in JavaScript, when .NET insists on mangling the name?

If you have controls such as:

<asp:radiobutton id="button1" runat="server" groupname="mygroup" />
<asp:radiobutton id="button2" runat="server" groupname="mygroup" />

then the output ends up being something like this

<input id="ctl00_contentholder_parent_button1"
name="ctl00$contentholder$parent$mygroup" />
<input id="ctl00_contentholder_parent_button2"
name="ctl00$contentholder$parent$mygroup" />

(this example comes from .NET 2, hence the contentholder text)

Now the element can be referenced using Control.ClientID, and that
value written to your JavaScript. However, there isn't a readily
accessible equivalent for GroupName. VS2005 gives a tantalising peek
when debugging, by showing a private property UniqueGroupName, which
contains the desired value of ctl00$contentholder$parent$mygroup, but
as it's private, it's not readily accessible.

Any thoughts, other than *ug* hard coding the reference and praying
that no-one renames something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top