对于我的网络应用程序,我尝试使用AsyncPostBackTrigger根据客户端点击日历扩展器(我在codebehind vb.net中声明从数据库加载它)来填充下拉列表(DDL)(因为我不想要页面)到autopostback)。我有一个按钮来激活所选的日期,它确实填充了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();
}
答案 0 :(得分:0)
没关系我已经弄明白了。当用户从日历中选择日期时,我使用ontextChanged作为文本框,并删除了OnClientDateSelectionChanged,触发器和虚拟按钮。我保留了UpdatePanel,它按照我想要的方式工作。