Riz
Riz

Reputation: 6676

how to access generated groupname for asp radiobutton

I need to access radiobutton groupname in my jquery. However, groupname that's rendered for an asp radiobutton is kind of different. Example:

<asp:RadioButton runat="server" GroupName="payment" ID="creditcard" Checked="true" value="creditcard" />

will generate:

<input type="radio" checked="checked" value="creditcard" name="ctl00$ContentPlaceHolder1$payment" id="ctl00_ContentPlaceHolder1_creditcard">

I can't work with <%=creditcard.GroupName%> in jquery. Is there a way I can get the generated groupname or name for it?

Upvotes: 3

Views: 4471

Answers (2)

Nick Craver
Nick Craver

Reputation: 630429

You can do this:

$("input[name$=payment]")

This uses the $= ends with selector, finding names that end with payment, as long as you don't have multiple of these across containers, it'll work.

Alternatively, to be based on this specific control:

$("input[name=<%=creditccard.GroupName %>]")

Upvotes: 8

hunter
hunter

Reputation: 63522

This will get you the proper group name

$("#<%=creditccard.ClientID %>").attr("name");

Upvotes: 7

Related Questions