Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  37] [ 7]  / answers: 1 / hits: 45225  / 15 Years ago, tue, may 5, 2009, 12:00:00

I have a CalendarExtender control on my page and sometimes have to change the date to the next occuring Sunday. I'm currently using the OnClientDateSelectionChanged property of the control to call a function that will add some days to the date until its Sunday.



The problem I'm having is that if I select a Tuesday in my calendar, the textbox will display the next Sunday but the selected date in the calendar is still Tuesday.



How do I update the CalendarExtender to have the new date that has one I selected in javascript? The textbox the CalendarExtendar is connected to shows the correct date...


More From » ajax

 Answers
69

Changing the value of the textbox that is the TargetControlId for the CalendarExtender affects the selected date if the following 2 conditions are met:




  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.



That being said, the correct way to handle this is to call the set_selectedDate() function of the CalendarExtender control. This one call, not only sets the selected on the Calendar, but also on the Targeted textbox at the same time.



Here's the example code:



<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>

[#99596] Thursday, April 30, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
agustindejonm

Total Points: 738
Total Questions: 84
Total Answers: 84

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
agustindejonm questions
Fri, Jun 25, 21, 00:00, 3 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Sat, May 16, 20, 00:00, 4 Years ago
;