简体   繁体   English

ASP.NET DropDownList SelectedIndexChanged与UpdatePanel AsyncPostBackTrigger

[英]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.

相关问题 ASP.NET MVC 5 DropDownList selectedindexchanged - ASP.NET MVC 5 DropDownList selectedindexchanged ASP.NET MVC 4 DropDownList selectedindexchanged - ASP.NET MVC 4 DropDownList selectedindexchanged 嵌套的ASP.NET DropDownList SelectedIndexChanged未触发 - Nested ASP.NET DropDownList SelectedIndexChanged Not Firing ASP.NET DropDownList未在SelectedIndexChanged上绑定SQL - ASP.NET DropDownList not binding SQL on SelectedIndexChanged ASP.NET 下拉列表 selectedIndexChanged 没有被触发 - ASP.NET dropdownlist selectedIndexChanged not getting triggered 在UpdatePanel中重新填充Asp.Net DropDownList - Repopulate Asp.Net DropDownList In UpdatePanel 如果将ASP.net链接按钮&#39;onclick&#39;用作UpdatePanel中的AsyncPostBackTrigger触发器,则不会触发 - ASP.net linkbutton 'onclick' does not trigger if it is used as an AsyncPostBackTrigger trigger in UpdatePanel asp.net dropdownlist的第一个选择不会触发SelectedIndexChanged事件 - asp.net dropdownlist first selection does not fire SelectedIndexChanged event ASP.NET MVC C#-DropDownList SelectedIndexChanged不触发 - Asp.net MVC C# - DropDownList SelectedIndexChanged not firing ASP.Net下拉列表没有返回selectedindexchanged事件的索引 - ASP.Net dropdownlist not returning index on selectedindexchanged event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM