Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax UpdatePanel and a dropdownlist trigger

    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

    Code:
    <asp:Panel ID="pnlDataBase" runat="server" Visible="false">
          <table>
            <tr>
              <td>
                <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:DropDownList>
              </td>
              <td>
                <asp:UpdatePanel ID="upnlDesc" runat="server" UpdateMode="conditional">
                  <ContentTemplate>
                    <asp:Label id="lblDesc" runat="server" />
                  </ContentTemplate>
                  <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="ddlDatabase" />
                  </Triggers>
                </asp:UpdatePanel>
              </td>
            </tr>
          </table>
        </asp:Panel>
    and the very simple selectedindexchanged (mstrDBDesc being a public string array with 3 diff strings):
    Code:
    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

  • #2
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •