我有一个下拉列表(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"
属性
关于asp.net - 下拉列表不会触发 SelectedIndexChanged,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4134851/