为什么 selectedindexchanged 没有触发?
我定义了以下 DropDownList:
<asp:DropDownList ID="ddlStuff" CssClass="myCssClass" OnSelectedIndexChanged="PopulateAnotherDropdown" runat="server"></asp:DropDownList>
但是,我的 PopulateAnotherDropdown 方法未触发。我在该方法上设置了断点,但没有被击中。
这是我在代码隐藏中编写的方法:
public void PopulateAnotherDropdown(object sender, EventArgs e)
{
...
}
对于它的价值,页面呈现如下:
<select name="ctl00$MainContent$ddlStuff" id="MainContent_ddlStuff" class="myCssClass">
有什么想法吗?
I have the following DropDownList defined:
<asp:DropDownList ID="ddlStuff" CssClass="myCssClass" OnSelectedIndexChanged="PopulateAnotherDropdown" runat="server"></asp:DropDownList>
However, my PopulateAnotherDropdown method isn't firing. I have a breakpoint set on the method, and it's not being hit.
Here is my method write-up in code-behind:
public void PopulateAnotherDropdown(object sender, EventArgs e)
{
...
}
For what it's worth, the page is rendering as follows:
<select name="ctl00$MainContent$ddlStuff" id="MainContent_ddlStuff" class="myCssClass">
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为您忘记添加:
AutoPostBack="true"
要触发 dropdownlist 控件的 SelectedIndex,它需要回发到服务器。为此,您必须在控件属性中设置
AutoPostBack="true"
。Because you forget to add:
AutoPostBack="true"
To fire the SelectedIndex of the dropdownlist control, it needs to postback to the server. For that to happen you to have to set
AutoPostBack="true"
in the control property.请设置
下拉菜单。因为默认情况下,除了按钮控制之外,它是 false
Please Set
of the dropdown.Because by default it is false except button control