c# - 为什么下拉事件在asp中不起作用

标签 c# asp.net

我的下拉列表其事件(不显示你好)不起作用......

aspx页面

<asp:DropDownList ID="DropDownList1" runat="server" 
    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem>1</asp:ListItem>
    <asp:ListItem>2</asp:ListItem>
    <asp:ListItem>3</asp:ListItem>
    <asp:ListItem>4</asp:ListItem>
    <asp:ListItem>5</asp:ListItem>
</asp:DropDownList>

aspx.cs页面

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    Console.WriteLine("Hello");
}

问题是,如果我在 console.writeline 中保留断点,它就不起作用...我犯错误的地方...任何想法。谢谢...

最佳答案

在您的 aspx 代码中添加 AutoPostBack="true",如下所示:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem>1</asp:ListItem>
    <asp:ListItem>2</asp:ListItem>
    <asp:ListItem>3</asp:ListItem>
    <asp:ListItem>4</asp:ListItem>
    <asp:ListItem>5</asp:ListItem>
</asp:DropDownList>

关于c# - 为什么下拉事件在asp中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20866166/

相关文章:

c# - 将 C 公式转换为 C#

ASP.Net 用户控件中的 Javascript Intellisense

元素内部的 ASP.NET Web 窗体元素

c# - WebForms 模型绑定(bind) : Automatically map updated values to Item

c# - html敏捷包: Find second table within a div

c# - 试图将 byte[] 转换为 jpg 文件

c# - 剪切图像的中心

c# - 如何修复网格行和列在 wpf 中不更新?

asp.net - session 超时在 ASP .Net 中不起作用

c# - 无法通过单击按钮发送电子邮件。 ASP.NET 和 C#