How to use RadioButtonList AutoPostBack in asp.net c#

AutoPostBack feature in RadioButtonList
The following asp.net c# example code demonstrate us how can we use RadioButtonList AutoPostBack property/feature. RadioButtonList is an asp.net list web server control which render a radio group in web page. RadioButtonList provide a single selection/check radio group. User's can select an item from RadioButtonList at a time.

We can get the user selection from a RadioButtonList after page submission to web server. RadioButtonList control has a property named 'AutoPostBack' which allow us to automatically submit the page to web server each time RadioButtonList item selection is change. AutoPostBack property accept a Boolean value.

If we set AutoPostBack property value to true then each time we change the RadioButtonList item selection, it post the web page to server. If we set AutoPostBack property value to false then it does not post the page to server when we change the RadioButtonList item selection.

If we set the RadioButtonList control's AutoPostback property value to true and write an event handler for SelectedIndexChanged event then we can get selected item's text and value each time user's change the item selection of RadioButtonList.
RadioButtonListAutoPostBack.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use AutoPostBack feature in RadioButtonList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">RadioButtonList: AutoPostBack</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Font-Size="Large"
             >
        </asp:Label>
        <br /><br />
        <asp:Label 
             ID="Label2"
             runat="server"
             Font-Bold="true"
             ForeColor="DarkCyan"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:RadioButtonList 
             ID="RadioButtonList1"
             runat="server"
             AutoPostBack="true"
             OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
             BackColor="DarkCyan"
             ForeColor="AliceBlue"
             >
             <asp:ListItem>HyperLink</asp:ListItem>
             <asp:ListItem>LayoutEditorPart</asp:ListItem>
             <asp:ListItem>BehaviorEditorPart</asp:ListItem>
             <asp:ListItem>Localize</asp:ListItem>
             <asp:ListItem>ImageMap</asp:ListItem>
        </asp:RadioButtonList>
    </div>
    </form>
</body>
</html>
More asp.net examples