下拉列表AJAX的SelectedIndexChanged事件 [英] SelectedIndexChanged Event for Dropdownlist AJAX
问题描述
你好,
感谢您的阅读.这是我的情况.我有一个UpdatePanel,并且里面有2个下拉列表.我只想在dropdownlist1中选择特定值时显示第二个ddlist.我在selectedIndexChanged事件上使用了Javascript/label等,但仍然无法正常工作.事件被触发,我顺利通过代码,但它没有在屏幕上呈现.下面的代码段.所有的帮助都非常,感谢和感激.
前端
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
推荐答案
不要将两个下拉列表都放在Same Update Panel中.将其放在两个不同的更新面板中,并为Second Updatepanel
创建UpdateMode="Conditional"
,然后从Dropdownlist1的SelectedIndexChanged事件中调用UpdatePanel2.Update().希望可以帮助您:-D
Do not put the both Dropdown list in Same Update Panel. Place it in two different Update Panel and Make theUpdateMode="Conditional"
for theSecond Updatepanel
and call UpdatePanel2.Update() from SelectedIndexChanged event of Dropdownlist1.
Hope this will help you :-D
这篇关于下拉列表AJAX的SelectedIndexChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!