OLDMONK OLDMONK - 2 months ago 10x
jQuery Question

Disable other RadioButtons in an Asp.net RadioButtonList if one among them is selected

I need to disable other asp.net radio buttons when one of them is selected.There are three radio buttons.Like for example is Cash radio button is selected,other two from the listitem should be disabled.I did some research and did disabled the other two when the third one is selected.But on my code behind page it gives me null value for the selectedradio button.here is my code:

My .aspx

<div class="col-sm-4" style="padding-top:4px ; margin-top:-8px">
<asp:RadioButtonList runat="server" ID="loanTypeCheck" CssClass="pull-right" RepeatDirection="Horizontal">
<asp:ListItem Value="Cash" Text="&nbsp;&nbsp;Cash&nbsp;&nbsp;"/>
<asp:ListItem Value="Non-Cash" Text="&nbsp;&nbsp;Non-Cash&nbsp;&nbsp;" />
<asp:ListItem Value="Dharauti" Text="&nbsp;&nbsp;Dharauti&nbsp;&nbsp;" />


My code behind

protected void SaveButton_Click(object sender, EventArgs e)

if (IsFormValidForSave())
var loanReceipt = GetLoanReceiptFromForm();
var transactionsDetails = new List<TransactionDetail>();

if (loanTypeCheck.SelectedValue == "Cash")

And here is my Js to disable the radio buttons

$('input[type=radio]').change(function () {
$("#<%=loanTypeCheck.ClientID %>").find('input').prop('disabled', true);

Everything works in the UI but i get null value in my loanTypeCheck.SelectedValue in code behind.
I came across questions like these only with UI part but not on getting the values for computing.Any Help Please.


You can set the disabled property for unselected radio buttons with the :not(:checked) selector:

$('#<%= loanTypeCheck.ClientID %>').change(function () {
    $(this).find('input[type=radio]:not(:checked)').prop('disabled', true);

Keeping the checked radio button enabled will allow the selected value to be posted back.