Link to home
Start Free TrialLog in
Avatar of Jon Winterburn
Jon WinterburnFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Ajax Toolkit CalendarExtender (VB.NET)

Hi experts,

I am using the Ajax Toolkit CalendarExtender on a form. I have three textbox controls (txt1stday, txtlastday and txtrtnday), each using it's own CalendarExtender control. Each CalendarExtender defaults to the current month.

I need to know how to do 2 things:

1. When a user selects a date in a different month (and/or year) to the current month in the first calendar, I want the second and third calendar to automatically change the month (and/or year) to match the month of the first calendar.

2. The Format property exists for the CalendarExtender control. But I cannot seem to change the format to be user-friendly. It defaults to dd/MM/yyy. I would like to display the date as: Thursday 28 May 2009 instead of 28/05/2009.

Any help would be appreciated.

Thanks

Jon
Avatar of David Robitaille
David Robitaille
Flag of Canada image


for 1 you have to change the SelectedDate of the others calendars (I think you need to postback to do this)

for 2 set the format to "Format="d MMMM  yyyy"

Avatar of Jon Winterburn

ASKER

The format thing is perfect - I just had to adjust it a bit to: dddd d MMMM yyyy - in order to get the day as well as the date. But thanks, that's brilliant - I should have tried 4 M's but didn't think of it!

I'll have a go at SelectedDate in the postback and come back to you.
Have you find how to postback? ex: you could set the target control to autopostback and then do your stuff in the text changed...
I have done some playing. I had to set:

CalendarExtender1.SelectedDate = DateTime.Now

...so that it populates the textbox, else it would not do anything. On clicking the calendar picker and changing the date, it postbacks CalendarExtender2 and then fills the second textbox with the same date as the first. Okay, but not ideal. Ideally I want all 3 textboxes blank to start with, CalendarExtender1 calendar to default to today (it does already) and when the date is picked, form postbacks and changes CalendarExtender2 to the right month and same date as CalendarExtender1 - but not populate textbox2 with said date.

Does that make sense? In the aspx page I added a property to CalendarExtender1:

OnClientDateSelectionChanged="function ddd(){__doPostBack('CalendarExtender2','') ;}"

...and in the code behind I added the attached:

If Page.IsPostBack Then
   CalendarExtender2.SelectedDate = CalendarExtender1.SelectedDate
       ElseIf Not Page.IsPostBack Then
          CalendarExtender1.SelectedDate = DateTime.Now
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Robitaille
David Robitaille
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, I'll go down that avenue if I have to. If I leave it as it is (with the dates populating the fields), I have only one problem. With my code as mentioned above, if I change the date of the first calendar, it momentarily changes before changing both itself and calendar2 to the current date! Even though I stated:

ElseIf Not Page.IsPostBack Then
          CalendarExtender1.SelectedDate = DateTime.Now
in witch function you put your code?
I would do it that way.
Page load :
If Not Page.IsPostBack Then
          CalendarExtender1.SelectedDate = DateTime.Now
End If
on the CalendarExtender1<s target text changed:
CalendarExtender2.SelectedDate =  CalendarExtender1.SelectedDate
 
 
Yup, that's exactly what I'm doing. So close to getting this working!
you must be doing something else then, did you pui a breakpoint in the page load to make sure the code is not executed?
This is madness. No matter where I add breaks, it makes no difference and just does the same thing.
?
adding break should help you to see whant hapenning... does the code getting executed as expected? you should be able to see where the CalendarExtender2`s value is changing back to now...
After reading up on this I have realised that changing the calendar itself, and not the textbox is not possible with this calendar. I will scrap it and start again with a different control. Thanks for your efforts.