Reputation: 381
<asp:ListBox ID="list1" runat="server" Height="200" Style=" margin: 0" OnSelectedIndexChanged="list1_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:ListBox>
i have listbox in the updatePanel
but when i select something it doesn't fire an event what am doing wrong?
Upvotes: 3
Views: 7381
Reputation: 15881
You need to Set AutoPostBack
Property to True. then only Postback happens and your selected index event will fire.
<asp:ListBox AutoPostBack="true" ID="yourLIst" runat="server" Height="200" Style=" margin: 0" OnSelectedIndexChanged="yourLIst_SelectedIndexChanged">
Upvotes: 10
Reputation: 460298
You have to set AutoPostBack
to true
(default is false
):
<asp:ListBox AutoPostBack="true" ID="list1" runat="server" Height="200" Style=" margin: 0" OnSelectedIndexChanged="list1_SelectedIndexChanged">
....
Also note that you have to databind the ListBox only on the initial load not on every postback, so use the IsPostBack
property to check it:
protected void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
DataBindListBox();
}
Upvotes: 6