Radio button to enable or disable textbox

1. Add a radiobutton list and textbox control. Add two list items “Yes” and “No” to radiobutton list. Also make sure radiobutton list has property AutoPostBack=”true” and event onselectedindexchanged added

<asp:RadioButtonList ID=”RadioButtonList1″ runat=”server”
            onselectedindexchanged=”RadioButtonList1_SelectedIndexChanged” AutoPostBack=”true” >
    <asp:ListItem Text=”Yes” Value=”1″ Selected=True></asp:ListItem>
    <asp:ListItem Text=”No” Value=”0″></asp:ListItem>
    <br />
    <asp:TextBox ID=”txtYesEnabled” runat=”server”></asp:TextBox>

2. Add implementation to onselectedindexchanged  event to enable or disable textbox based on selection of radio button list

 protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        if (RadioButtonList1.SelectedIndex== 0)
            txtYesEnabled.Enabled = true;
            txtYesEnabled.Enabled = false;

Happy Coding

Leave a Reply

%d bloggers like this: