How to use AutoPostBack in asp.net c# CheckBoxList

AutoPostBack feature in CheckBoxList
CheckBoxList is an ASP.NET web server control. This server control creates a multi-selection CheckBox group. CheckBoxList can be dynamically populated by binding the data source.

CheckBoxList AutoPostBack property gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the CheckBoxList selection. This property value type is a Boolean.

If we set the property value to true then a postback automatically occurs when the user changes the CheckBoxList selection. And if we set this property value to false then automatic postback to the server will be disabled. The default value of this property is false.

CheckBoxList SelectedIndexChanged event occurs when the selection of CheckBoxList changes between posts to the server. to work this event properly we need to set the CheckBoxList AutoPostBack property value to true.

The following ASP.NET C# example code demonstrates to us how can we use the AutoPostBack property of CheckBoxList in an ASP.NET application.
CheckBoxListAutoPostBack.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void CheckBoxList1_SelectedIndexChnaged(object sender, System.EventArgs e)
    {
        Label1.Text = "You Selected:<br /><i>";
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected == true)
            {
                Label1.Text += li.Text + "<br />";
            }
        }
        Label1.Text += "</i>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use AutoPostBack feature in CheckBoxList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Maroon">CheckBoxList: AutoPostBack</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Font-Size="Large"
             >
        </asp:Label>
        <br />
        <asp:Label 
             ID="Label2"
             runat="server"
             Font-Bold="true"
             ForeColor="DarkBlue"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:CheckBoxList 
             ID="CheckBoxList1"
             runat="server"
             AutoPostBack="true"
             OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChnaged"
             >
             <asp:ListItem>Image</asp:ListItem>
             <asp:ListItem>TreeView</asp:ListItem>
             <asp:ListItem>Literal</asp:ListItem>
             <asp:ListItem>ValidationSummary</asp:ListItem>
             <asp:ListItem>MultiView</asp:ListItem>
        </asp:CheckBoxList>
    </div>
    </form>
</body>
</html>