DropDownList的OnSelectedIndexChanged不会触发

时间:2021-07-22 03:26:42

I created these DropDownLists:

我创建了这些DropDownLists:

<asp:DropDownList CssClass="ComboBoxes" ID="UserComboBox" runat="server" OnSelectedIndexChanged="UserComboBoxSelected"/>
<asp:DropDownList CssClass="ComboBoxes" ID="ShiftComboBox" runat="server"/>

I have this in the code-behind:

我在代码隐藏中有这个:

protected void UserComboBoxSelected(object sender, EventArgs e)
{
    // ...
}

However, it never fires when I select items in UserComboBox. What am I doing wrong?

但是,当我在UserComboBox中选择项目时,它永远不会触发。我究竟做错了什么?

2 个解决方案

#1


4  

You have to set [AutoPostBack][1] to true for firing event on server side code behind file.

您必须将[AutoPostBack] [1]设置为true才能在文件后面的服务器端代码上触发事件。

<asp:DropDownList CssClass="ComboBoxes" ID="UserComboBox" runat="server" AutoPostBack="true" OnSelectedIndexChanged="UserComboBoxSelected"/>

Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection, MSDN.

获取或设置一个值,该值指示当用户更改列表选择MSDN时是否自动发生到服务器的回发。

#2


1  

<asp:DropDownList 
    CssClass="ComboBoxes" 
    ID="UserComboBox" 
    runat="server" 
    OnSelectedIndexChanged="UserComboBoxSelected" 
    AutoPostBack="true" />

#1


4  

You have to set [AutoPostBack][1] to true for firing event on server side code behind file.

您必须将[AutoPostBack] [1]设置为true才能在文件后面的服务器端代码上触发事件。

<asp:DropDownList CssClass="ComboBoxes" ID="UserComboBox" runat="server" AutoPostBack="true" OnSelectedIndexChanged="UserComboBoxSelected"/>

Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection, MSDN.

获取或设置一个值,该值指示当用户更改列表选择MSDN时是否自动发生到服务器的回发。

#2


1  

<asp:DropDownList 
    CssClass="ComboBoxes" 
    ID="UserComboBox" 
    runat="server" 
    OnSelectedIndexChanged="UserComboBoxSelected" 
    AutoPostBack="true" />