English 中文(简体)
使用Javascript CalendarExtender改变日期
原标题:
  • 时间:2009-05-05 14:12:05
  •  标签:

我有CalendarExtender控制页面,有时必须改变下一个周日发生的日期。我目前使用的OnClientDateSelectionChanged属性控制调用一个函数,将添加一些天日期直到星期天。

我在的问题是,如果我选择一个星期二在日历,文本框将显示下个星期天,但所选日期的日历仍然是星期二。

我怎么更新CalendarExtender有新的日期,我有一个javascript中选择吗?文本框CalendarExtendar连接到显示正确的日期…

最佳回答

改变文本框的值就是TargetControlId CalendarExtender影响所选日期如果满足以下2个条件:

  1. An onchange event is fired on the textbox (either by changing the text manually or by calling an explicit javascript fireEvent() method.
  2. The format of the date entered in the textbox matches the same format used by the CalendarExtender control.

也就是说,正确的处理这个问题的方法是调用set_selectedDate CalendarExtender控制的()函数。这一个电话,不仅设置日历上的选择,但也同时有针对性的文本框。

下面的示例代码:

<cc1:CalendarExtender ID="CalendarExtender1" runat="server" 
        OnClientDateSelectionChanged="dateSelectionChanged" 
        TargetControlID="txtDate" PopupButtonID="imgCalendar">
</cc1:CalendarExtender>

<script type="text/javascript">
  function dateSelectionChanged(sender, args){
    selectedDate = sender.get_selectedDate();
    /* replace this next line with your JS code to get the Sunday date */
    sundayDate = getSundayDateUsingYourAlgorithm(selectedDate); 
    /* this sets the date on both the calendar and textbox */
    sender.set_SelectedDate(sundayDate); 
 }
</script>
问题回答
<asp:TextBox ID="txtDate" Text= <%# Bind("Date", "{0:dd-MMM-yyyy}") %> 
                                                                                            runat="server" class="form-control input-sm m-bot15" BackColor="#ffccbb"></asp:TextBox>
                                                                                        <asp:CalendarExtender ID="CalExtender1" runat="server" Enabled="true" Format="dd-MMM-yyyy"
                                                                                            TargetControlID="txtDate">
                                                                                        </asp:CalendarExtender>




相关问题
热门标签