Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SelectedIndexChanged Event for Dropdownlist AJAX

SelectedIndexChanged Event for Dropdownlist AJAX

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadmintoolshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ridge Howison
    wrote on last edited by
    #1

    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()

    A A 2 Replies Last reply
    0
    • R Ridge Howison

      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()

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

      1 Reply Last reply
      0
      • R Ridge Howison

        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()

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        Hey... Why do you require to pass a script to the client and process to change the visibility of the control, when you simply can change Me.ddlTest2.Visible = false By this way you are eventually making your response smaller, as if a servercontrol visible is false, it will not rendered to the client. :rose: Or if you need Javascript fix, just use simple AJAX call (May be using ICallBackEventHandler) from the Javascript, and get the status of the Clientside control, and do display=none from javascript. Dont need UpdatePanel for such a small need.. .:rose::rose:

        Abhishek Sur My Latest Articles Working with Excel using MDAC
        Basics on LINQ and Lambda Expressions
        Create .NET Templates

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups