Jamesla Jamesla - 4 months ago 14
Ajax Question

Control event not firing from within updatepanel

I have a listbox that is being updated via a timer and working as expected inside an UpdatePanel.

However I cannot get the selectedindexchanged event to fire. I presume this is something to do with the partial postback. Does anybody know what I can do to make this work?

When I move it out of the UpdatePanel it works fine. However obviously I cannot do partial postbacks.

<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>


UPDATE:

Have now tried the below change, the timer event is still working but the selectedindexchanged event is not. I am getting lost with this.

<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>




Here is the event that does not fire when the listbox is inside the UpdatePanel but does work when it is not.

protected void ListBox_JobPositions_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("test");
}

Answer

Works now, had to manually specify Async and Full Postback triggers. Thanks for your help.

<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
    <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
    <asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" />
    <asp:PostBackTrigger ControlID="ListBox_JobPositions" /> 
</Triggers>
</asp:UpdatePanel>