c# - 为什么 selectedindexchanged 不触发?

标签 c# .net asp.net drop-down-menu code-behind

我定义了以下 DropDownList:

<asp:DropDownList ID="ddlStuff" CssClass="myCssClass" OnSelectedIndexChanged="PopulateAnotherDropdown" runat="server"></asp:DropDownList>

但是,我的 PopulateAnotherDropdown 方法没有触发。我在该方法上设置了一个断点,它没有被击中。

这是我在代码隐藏中编写的方法:
public void PopulateAnotherDropdown(object sender, EventArgs e)
{
    ...
}

对于它的值(value),页面呈现如下:
<select name="ctl00$MainContent$ddlStuff" id="MainContent_ddlStuff" class="myCssClass">

有任何想法吗?

最佳答案

因为您忘记添加:AutoPostBack="true"
要触发下拉列表控件的 SelectedIndex,它需要回发到服务器。为此,您必须设置 AutoPostBack="true"在控件属性中。

关于c# - 为什么 selectedindexchanged 不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6818819/

相关文章:

SQL Server Service Broker 的 .NET API

基于查询字符串 ID 的 ASP.net URL 重写

c# - 重复函数

c# - 如何将参数传递给 ASP.NET MVC 2 中的自定义 ActionFilter?

c# - 创建 NuGet 包时,如何为程序集指定框架版本?

c# - 如何在 c# 中为 Microsoft.office.interop.word 实现后期绑定(bind)?

.net - 仅在持续集成服务器上进行 ClickOnce 签名

c# - 自定义与非自定义属性?

asp.net - 实现 .NET OAuth 2.0 提供程序。 2 Legged DotNotOpenAuth 样本?

c# - WebAPI 路由模板中的通配符