[英]ASP.NET DropDownList SelectedIndexChanged with UpdatePanel AsyncPostBackTrigger
My DDL doesn't work with SelectedIndexChanged, or rather it only worked for the first time. 我的DDL不能与SelectedIndexChanged一起使用,或者只能是第一次使用。 Second time onward it doesn't trigger the drpItemType_SelectedIndexChanged method anymore.
第二次以后,它不再触发drpItemType_SelectedIndexChanged方法。
ASPX ASPX
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="drpItemType" runat="server" CssClass="drpDown" Width="370px" OnSelectedIndexChanged="drpItemType_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Computer (Desktop/Laptop)" Value="PC"></asp:ListItem>
<asp:ListItem Text="Others" Value="Others"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblID1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpItemType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Code Behind 背后的代码
protected void drpItemType_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpItemType.SelectedValue == "PC")
{
lblID1.Text = "PC";
}
else if (drpItemType.SelectedValue == "Others")
{
lblID1.Text = "Others";
}
}
Actually your code works fine. 实际上,您的代码可以正常工作。 I copied it and pasted it into a new project and it runs fine every time.
我将其复制并粘贴到新项目中,每次运行都很好。 Try it yourself.
自己尝试。 I think you have something else on your page which is causing a JavaScript error, and stopping subsequent postbacks from working.
我认为您的网页上还有其他内容会导致JavaScript错误,并阻止后续的回发工作。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.