View Full Version : Ajax UpdatePanel and a dropdownlist trigger

04-04-2007, 09:44 PM
I have an ajax update panel with a very simple label. For the moment I don't have any particular data to display, so I just made a string array to determine what to display when i change the dropdownlist index. Works fine, here's the asp code

<asp:Panel ID="pnlDataBase" runat="server" Visible="false">
<asp:DropDownList ID="ddlDatabase" runat="server" AutoPostBack="true" Width="120">
<asp:ListItem Text="Database 1" Value="0" />
<asp:ListItem Text="Database 2" Value="1" />
<asp:ListItem Text="Database 3" Value="2" />
<asp:UpdatePanel ID="upnlDesc" runat="server" UpdateMode="conditional">
<asp:Label id="lblDesc" runat="server" />
<asp:AsyncPostBackTrigger ControlID="ddlDatabase" />

and the very simple selectedindexchanged (mstrDBDesc being a public string array with 3 diff strings):

Protected Sub ddlDatabase_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ddlDatabase.SelectedIndexChanged

lblDesc.Text = mstrDBDesc(ddlDatabase.SelectedItem.Value)
End Sub

The problem is, when it causes the postback, the selectedindex is always 0, no matter what I'll choose in the dropdown. It's not dynamically generated, and the item count is there when the even is executed (I checked). So what am I doing wrong here? It's probably a tiny stupid detail I missed, but it's annoying and maybe a fresh eye might see it quicker than my tired blinking one.

Thanks for any help :D

04-17-2007, 06:31 PM
well, know what. I was lame enough to be setting the index in the page load as i used to do back when i was working with VB.Net Windows Form projects ^^. So removing that fixed it :P. I also moved the ddl in the update panel, and removed the triggers. Works great now. :rolleyes: