locked
How to disable text click on Radio button RRS feed

  • Question

  • User2011009134 posted

    Hi All,

    I just want to share with you a fix in case if you want to disable text click on radio button.

    Normal behaviour of RadioButtonList is the item will get selected when we click on its text.

    To avoid that, we can use label inside each list as given below.

    <asp:RadioButtonList ID="rdo" runat="server" AutoPostBack="true">
    <asp:ListItem Value="opt1"><label>Option 1</label></asp:ListItem>
    <asp:ListItem Value="opt2"><label>Option 2</label></asp:ListItem>
    <asp:ListItem Value="opt3"><label>Option 3.</label></asp:ListItem>
    </asp:RadioButtonList>


    Thanks

    Thursday, March 13, 2014 3:16 AM

All replies

  • User-1538266409 posted

    try like this it will work......

    rdo.items(0).selected==true

    {

    // txtboxname.text="";

    // txtboxname.enabled=false;

    }

    Friday, March 14, 2014 3:00 AM
  • User-417640953 posted

    Hi firos,

    Thanks for your post and solution for how to disable the RadioButtonList's text can be clicked.

    For this issue, we can also complete it using javascript like below.

     <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script>
            $(function () {
                $(".MyradioButtonlist").find("label").click(function () {
                    window.returnValue = false;
                    return window.returnValue;
    
                });
    
            })
     </script>
      <asp:RadioButtonList ID="rdo" runat="server" AutoPostBack="true" CssClass="MyradioButtonlist" >
            <asp:ListItem Value="opt1"> Option 1 </asp:ListItem>
            <asp:ListItem Value="opt2"> Option 2 </asp:ListItem>
            <asp:ListItem Value="opt3"> Option 3 </asp:ListItem>
      </asp:RadioButtonList>

    Thanks.

    Best Regards!

    Saturday, March 15, 2014 9:48 AM