次の2つの条件が満たされた場合、 CalendarExtenderのTargetControlIdであるテキストボックスの値を変更すると、選択した日付に影響します。
- onchangeイベントは、テキストボックスで発生します(テキストを手動で変更するか、明示的なjavascript fireEvent()メソッドを呼び出すことによって)。
- テキストボックスに入力された日付の形式は、CalendarExtenderコントロールで使用されているのと同じ形式と一致します。
そうは言っても、これを処理する正しい方法set_selectedDate()は、CalendarExtenderコントロールの関数を呼び出すことです。この1回の呼び出しで、選択したものがカレンダーだけでなく、[ターゲット]テキストボックスにも同時に設定されます。
サンプルコードは次のとおりです。
<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>