asp.net – Dropdownlist不会触发SelectedIndexChanged

我有一个下拉列表(dr1),它应该在不影响dr3的情况下触发dr2的更新.问题是dr1触发了更新,但没有进入dr1_SelectedIndexChanged.我知道,因为标签没有改变,暂停不会发生

这是我的HTML代码:

<form runat="server">
<asp:ScriptManager ID="sm" runat="server" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="5">
    <ProgressTemplate>
        <span style="color: Red">Updating.....</span>
    </ProgressTemplate>
</asp:UpdateProgress>
<asp:DropDownList ID="dr1" AutoPostBack="true" OnSelectedIndexChanged="dr1_SelectedIndexChanged" runat="server" />
<asp:UpdatePanel ID="updpnl" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="dr2" runat="server" />
        <asp:Label ID="lbl" runat="server" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="dr1" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
<asp:DropDownList ID="dr3" runat="server" />
</form>

和我的代码隐藏:

void Page_Load()
        {
            if (!IsPostBack)
            {
                java.Text = "<script language=\"JavaScript1.2\" type=\"text/javascript\">var sess = \"" + Session["username"] + "\";var user = \"" + Request.ServerVariables["LOGON_USER"].Replace("\\", "\\\\") + "\";</script>";
                dr1.Items.Clear();
                dr2.Items.Clear();
                dr3.Items.Clear();
                dr1.Items.Add("");
                dr1.Items.Add("A");
                dr1.Items.Add("B");
                dr1.Items.Add("C");
                dr1.Items.Add("D");
                dr3.Items.Add("");
                dr3.Items.Add("Allo");
                dr3.Items.Add("Bonjour");
                dr3.Items.Add("Ola");
            }
        }

        protected void dr1_SelectedIndexChanged(Object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
            lbl.Text = DateTime.Now.ToString();
            dr2.Items.Clear();
            dr2.Items.Add("");
            for (int i = 1; i <= 4; i++)
                dr2.Items.Add(dr1.SelectedValue + i);
        }

我希望有人可以帮助我

谢谢

最佳答案 尝试修改此行

 < asp:AsyncPostBackTrigger ControlID =“dr1”EventName =“SelectedIndexChanged”/>

并删除EventName =“SelectedIndexChanged”属性

点赞