asp.net - Enable and disable a RadioButtonList programmatically

Enable and disable RadioButtonList programmatically
The following asp.net c# example code demonstrate us how can we enable or disable a RadioButtonlist control programmatically at run time. RadioButtonList is an asp.net list web server control which encapsulate a group of radio button controls. RadioButtonList control has a built in property to switch between RadioButtonList control's enable and disable state.

RadiobuttonList control's Enabled property allow us to get or set a value indicating whether the RadioButtonList control is enabled. RadiobuttonList control's Enabled property accept a Boolean value.

If we set this property value to 'True', then it indicate the control is enabled and users can select/check item from it. If we set Enabled property value to 'False', then users cannot select any item from the RadioButtonList and the control goes to disabled state. Typically a disable control appears as dimmed in web browser.
RadioButtonListDisable.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        RadioButtonList1.Enabled = false;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        RadioButtonList1.Enabled = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to enable, disable RadioButtonList programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">RadioButtonList: Enable, Disable</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:RadioButtonList 
             ID="RadioButtonList1"
             runat="server"
             BackColor="SeaGreen"
             ForeColor="Snow"
             >
             <asp:ListItem>UpdateProgress</asp:ListItem>
             <asp:ListItem>CompareValidator</asp:ListItem>
             <asp:ListItem>RegularExpressionValidator</asp:ListItem>
             <asp:ListItem>ImportCatalogPart</asp:ListItem>
             <asp:ListItem>DeclarativeCatalogPart</asp:ListItem>
        </asp:RadioButtonList>
        <br /><br />
        <asp:Button 
             ID="Button1"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Text="Disable RadioButtonList"
             OnClick="Button1_Click"
             />
        <asp:Button 
             ID="Button2"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Text="Enable RadioButtonList"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples