Reputation: 36
My DDL doesn't work with SelectedIndexChanged, or rather it only worked for the first time. Second time onward it doesn't trigger the drpItemType_SelectedIndexChanged method anymore.
ASPX
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="drpItemType" runat="server" CssClass="drpDown" Width="370px" OnSelectedIndexChanged="drpItemType_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Computer (Desktop/Laptop)" Value="PC"></asp:ListItem>
<asp:ListItem Text="Others" Value="Others"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblID1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpItemType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Code Behind
protected void drpItemType_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpItemType.SelectedValue == "PC")
{
lblID1.Text = "PC";
}
else if (drpItemType.SelectedValue == "Others")
{
lblID1.Text = "Others";
}
}
Upvotes: 2
Views: 11017
Reputation: 3720
Actually your code works fine. I copied it and pasted it into a new project and it runs fine every time. Try it yourself. I think you have something else on your page which is causing a JavaScript error, and stopping subsequent postbacks from working. Hope this helps.
Upvotes: 1