DropDownList 的 SelectedIndexChanged 事件未触发 [英] DropDownList's SelectedIndexChanged event not firing
问题描述
我的网页中有一个 DropDownList 对象.当我点击它并选择一个不同的值时,没有任何反应,即使我有一个连接到 SelectedIndexChanged
事件的函数.
I have a DropDownList object in my web page. When I click on it and select a different value, nothing happens, even though I have a function wired up to the SelectedIndexChanged
event.
首先,实际对象的 HTML 代码:
First, the actual object's HTML code:
<asp:DropDownList ID="logList" runat="server"
onselectedindexchanged="itemSelected">
</asp:DropDownList>
这就是那个函数,itemSelected
:
protected void itemSelected(object sender, EventArgs e)
{
Response.Write("Getting clicked; " + sender.GetType().ToString());
FileInfo selectedfile;
Response.Write("<script>alert('Hello')</script>");
foreach (FileInfo file in logs)
{
if (file.Name == logList.Items[logList.SelectedIndex].Text)
{
Response.Write("<script>alert('Hello')</script>");
}
}
}
没有任何响应出现,并且 JavaScript 的那部分永远不会运行.我已经在最新的 3.6 版本的 Firefox 和 Internet Explorer 8 上尝试过这个.这是从 Windows Server 2003 R2 机器上提供的,运行 ASP.NET 和 .NET Framework 版本 4.
None of the Responses appear, and that portion of JavaScript is never run. I've tried this on the latest 3.6 version of Firefox, as well as Internet Explorer 8. This is being served from a Windows Server 2003 R2 machine, running ASP.NET with the .NET Framework version 4.
推荐答案
将 DropDownList AutoPostBack
属性设置为 true.
Set DropDownList AutoPostBack
property to true.
例如:
<asp:DropDownList ID="logList" runat="server" AutoPostBack="True"
onselectedindexchanged="itemSelected">
</asp:DropDownList>
这篇关于DropDownList 的 SelectedIndexChanged 事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!