Click here to Skip to main content
14,879,343 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hello,

Thank you for reading. Here is my situation. I have an UpdatePanel and within in I have 2 dropdownlists.   I want to show the second ddlist only when a specific value is chosen in dropdownlist1. I used Javascript/label etc on the selectedIndexChanged event but still does not work. The event gets fired and I stepped thru the code with no problems but it does not render on screen. Code snippet below. All help is wonderfully,gratefully and thankfully appreciated.

Front End
<asp:UpdatePanel ID="updPanel1" runat="server">
            <ContentTemplate>
          <asp:DropDownList ID="ddlTest1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTest1_IndexChanged">
            <asp:ListItem Value="" Text="Select one"></asp:ListItem>
            <asp:ListItem Value="Matt" Text="Matt"></asp:ListItem>
            <asp:ListItem Value="Robin" Text="Robin"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="ddlTest2" runat="server" style="visibility:hidden;display:none;">
            <asp:ListItem Text="Select One" Value=""></asp:ListItem>
            <asp:ListItem Text="Tom" Value="Tom"></asp:ListItem>
            <asp:ListItem Text="John" Value="John"></asp:ListItem>
            
      </asp:DropDownList>
</ContentTemplate>
            </asp:UpdatePanel>
And the Codebehind is as follows:

Protected Sub ddlTest1_IndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            If ddlTest1.SelectedValue = "Robin" Then

                  Dim script As String = "<script type='text/javascript'>var elem=document.getElementById('" & Me.ddlTest2.ClientID & "');elem.style.visibility='visible';elem.style.display='block';</script>
          
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "newKeyVal", script, True)
                  
            Else
                  Dim script As String = "<script type='text/javascript'>var elem=document.getElementById('" & Me.ddlTest2.ClientID & "');elem.style.visibility='hidden';elem.style.display='block';</script>"
                  Page.ClientScript.RegisterClientScriptBlock(Me.GetType (), "newKeyVal", script, True)
                  
            End If

      End Sub
Posted
Updated 20-Feb-10 7:05am
v2

1 solution

Do not put the both Dropdown list in Same Update Panel. Place it in two different Update Panel and Make the UpdateMode="Conditional" for the Second Updatepanel and call UpdatePanel2.Update() from SelectedIndexChanged event of Dropdownlist1.

Hope this will help you :-D

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900