【发布时间】:2013-11-12 21:11:29
【问题描述】:
我有一个带有 onSelectedIndexChanged 事件的 ASP.NET DropDownList 控件。我也有许多人说可以解决问题的 AutoPostBack="true"。但是我不认为这就是问题所在……我的 Html 代码和 C# 代码在下面供参考。问题是代码有效,但只有当我在编辑下拉框时按下回车键时。如果我只是单击下拉列表中的对象,则不会触发该事件。如果我更改所选项目,因此下拉菜单中的“所选”文本显示为“ASP”,然后我使用浏览器检查该元素,我看到 ListItem 的 Selected="True" 部分仍在第一个项目上。 . 它在那里没有改变。它用回车键改变,但不是用鼠标点击。欢迎提供任何帮助并非常感谢。
HTML:
<div class="ui-widget">
<asp:DropDownList id="Select1" OnSelectedIndexChanged="Select1_SomethingChange" runat="server" AutoPostBack="true">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Select one...">Select one...</asp:ListItem>
<asp:ListItem Value="ActionScript">ActionScript</asp:ListItem>
<asp:ListItem Value="AppleScript">AppleScript</asp:ListItem>
<asp:ListItem Value="Asp">Asp</asp:ListItem>
<asp:ListItem Value="BASIC">BASIC</asp:ListItem>
</asp:DropDownList>
</div>
C#:
protected void Select1_SomethingChange(object sender, EventArgs e)
{
//something is meant to happen here
}
【问题讨论】:
-
将 autopostback="true" 更改为 AutoPostBack="true"
-
我在问题中输入它,它在代码中...我没有从代码中复制
-
我编辑了这个问题,现在应该是...抱歉造成混淆