使用 AsyncPostBackTrigger 填充现有下拉列表,而不是填充新的下拉列表

Populating existing dropdownlist using AsyncPostBackTrigger, not populate a new dropdownlist

本文关键字:填充 下拉列表 使用 AsyncPostBackTrigger      更新时间:2023-09-26

对于我的 Web 应用程序,我尝试根据客户端单击日历扩展器(我在代码隐藏中声明了这一点(填充下拉列表 (DDL( vb.net 从数据库加载它(使用 AsyncPostBackTrigger(因为我不希望页面自动回发(。我有按钮来触发所选日期,它确实可以填充 DDL,但不是我想要的方式。它不是在现有 DDL 中更新它,而是在现有 DDL 之外创建一个新的 DDL。我试图寻找解决方案,但没有找到任何解决方案。任何人都可以帮助我弄清楚为什么会发生这种情况以及如何解决此问题?

这是我的 asp.net 和javascript代码


<asp:Label ID="label16" runat = "server" Text="Select the date"></asp:Label></td>
                                            <td id="Td29" style="width:290px;" runat="server">
                                            <asp:TextBox ID="tbPostingDt" runat="server" style ="width:174px;"></asp:TextBox>
                                            <asp:Button ID="ClickBtn" runat="server" Text="Click"  style="display:none" OnClick="ClickBtn_Click" />
                                                <asp:ImageButton ID="CalendarBtnPostingDt" runat="server" ImageUrl="~/Images/Calendar_scheduleHS.png" AlternateText="Click to display calendar"/>
                                                <cc1:CalendarExtender ID="calPost" runat="server" PopupButtonID="CalendarBtnPostingDt" 
                                                    TargetControlID="tbPostingDt" OnClientDateSelectionChanged="dateSelectionChanged" Format="dd-MMM-yyyy" Enabled="True"></cc1:CalendarExtender></td>
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                                              <ContentTemplate>
                                                <asp:Label ID="label18" runat = "server" Text="Post Cycle No"></asp:Label></td>
                                            <td id="Td33" style="width:290px;" runat="server">
                                                <asp:DropDownList ID = "ddlPostCycleNo" runat = "server" style ="width:180px;">
                                                    <asp:ListItem>ALL</asp:ListItem>
                                                </asp:DropDownList> </td>
                                                </ContentTemplate>
                                                <Triggers>
                                                <asp:AsyncPostBackTrigger ControlID="ClickBtn" EventName="Click" />
                                                </Triggers>
                                                </asp:UpdatePanel>

    function dateSelectionChanged(sender, args) {
    var PostingDt = document.getElementById('<%= tbPostingDt.ClientID%>').value.trim();
    var clickButton = document.getElementById("<%= ClickBtn.ClientID %>");
    clickButton.click();
} 

关系,我已经想通了。当用户从日历中选择日期时,我使用了ontextChanged的文本框,并删除了OnClientDateSelectionChanged,触发器和虚拟按钮。我保留了UpdatePanel,它以我想要的方式工作。