【问题标题】:ASP Dropdown OnSelectedIndexChange event doesn't fireASP Dropdown OnSelectedIndexChange 事件不会触发
【发布时间】:2013-03-11 01:02:48
【问题描述】:

我已经阅读了很多关于此的文章和问题。但仍然没有找到我的案例的答案。 该函数处理事件。它根本不起作用 我的代码:

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Popup.aspx.cs"
     Inherits="GG.UI.Popup" %>
...

<asp:DropDownList ID="LEDropdown" runat="server" AutoPostBack="true" 
                  OnSelectedIndexChanged="LEDropdown_Change" ></asp:DropDownList>

ASPX.CS

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      PopulateClist();
      BindGrid();
   }
}
protected void PopulateClist()
{
   LEDropdown.Items.Clear();
   LEDropdown.Items.Add(new ListItem("First Item", "First");
   LEDropdown.Items.Add(new ListItem("Second Item", "Second");
   LEDropdown.SelectedIndex = 0;
}
protected void LEDropdown_Change(object sender, EventArgs arg)
{
   string selectedLE = ((DropDownList)(sender)).SelectedValue;
   ClientScript.RegisterStartupScript(GetType(), "Alert", "alert('" + selectedLE + "');");
}

我尝试在此页面和母版页中使用EnableViewState="true"。没有成功。
函数 LEDropdown_Change 从未被调用过。
页面在选择后仍然回传。

还有另一个带有 OnClick 事件的按钮,它工作正常。

【问题讨论】:

    标签: asp.net events drop-down-menu event-handling


    【解决方案1】:
    <asp:DropDownList ID="LEDropdown" runat="server" AutoPostBack="true" OnSelectedIndexChanged="LEDropdown_Change" ></asp:DropDownList>
    

    您的下拉列表正在调用LEDropdown_Change

    但你的 onchange 事件被称为:LegalEntityDropdown_Change

    【讨论】:

    • 对不起,我的错。我编辑了函数名称,使其更短且更易于阅读……不是这个问题。我更新了我的问题。感谢您发现它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多