SelectedIndexChanged Event for Dropdownlist AJAX
-
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()
-
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()
Do not put the both Dropdown list in Same Update Panel. Place it in two different Update Panel and Make the
UpdateMode="Conditional"
for theSecond Updatepanel
and call UpdatePanel2.Update() from SelectedIndexChanged event of Dropdownlist1. Hope this will help you :-DAbhijit 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
-
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()
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 dodisplay=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