Asp.net
DropDownList 的 SelectedIndexChanged 事件未觸發
我的網頁中有一個 DropDownList 對象。當我點擊它並選擇一個不同的值時,什麼也沒有發生,即使我有一個連接到
SelectedIndexChanged事件的函式。首先,實際對象的 HTML 程式碼:
<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。
將 DropDownList
AutoPostBack屬性設置為 true。例如:
<asp:DropDownList ID="logList" runat="server" AutoPostBack="True" onselectedindexchanged="itemSelected"> </asp:DropDownList>