This is a migrated thread and some comments may be shown as answers.

Problem with the preselected date

4 Answers 60 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Pams
Top achievements
Rank 1
Pams asked on 07 Sep 2011, 06:18 PM
Hello,
I have a screen with the date picker. User will select a date.
Under button click another page will be shown in popup. This page will have calender. In its page load I am preselecting the date which the user has already selected in the main screen. User shouldn't be able to unselect that preselected date.
I used the following code disable the selection

// if you are using the skin bundled as a webresource("Default"), the Skin property returns empty string
                string calendarSkin = RadCalendar1.Skin != "" ? RadCalendar1.Skin : "Default";
                string otherMonthCssClass = String.Format("otherMonth_{0}", calendarSkin);
                // disable the selection for the specific day
                RadCalendarDay calendarDay = new RadCalendarDay();
                calendarDay.Date = transactionDate; //the date which has to be preselected
                calendarDay.IsSelectable = false;
                calendarDay.ItemStyle.CssClass = otherMonthCssClass;
                RadCalendar1.SpecialDays.Add(calendarDay);

                //Pre select the transaction date selected in the entry screen
                RadCalendar1.SelectedDates.Add(new RadDate(transactionDate));

The probelm here is
After page load, the transactionDate is preselected which is fine. If I change the month, select different dates and come back to the month having preselected date, then I see that it is not preselected. Its selection is still disabled but it is not highlighted.

If I put just this code   
                        RadCalendar1.SelectedDates.Add(new RadDate(transactionDate));
and remove the code where the date is disabled,  then everything works fine.

Any help would be appreciated,
Thanks,
AV

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 12 Sep 2011, 03:57 PM
Hello Pams,

Could you please elaborate a bit more on what you are trying to achieve? Do you want to completely disable the date selection for the picker, or you want to disable a particular date?

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Pams
Top achievements
Rank 1
answered on 27 Sep 2011, 03:19 PM
Hello lana,
Thanks for your reply.
Actually user can enter some details for particular date which is 'transactiondate'. We are allowing the user to copy the same details to different dates.
So in actual screen, there will be date picker where they can select actual 'transactiondate' and enter all the details. 
When they click copy button, we are showing a popup screen where a calender is displayed.
Ex: Actual 'transactiondate'  is Sep 15 of 2011
Copied dates: Sep 17, Sep 19 , Sep 24 and Sep 29 of 2011

The user shouldn't be able to select Sept 15 again in the popup calender bcz it is already selected in the main details. 
To solve this, I tried to preselect Sept 15 2011 in the popup calender, so that user will think it is already selected.
User should n't be able to unselect that date in the popup calender. They can only change that date in main screen. So, I tried to disable the selection option for that specific date.

I used following code to preselect date and also disable the selection 

I used the following code disable the selection 
                 // if you are using the skin bundled as a webresource("Default"), the Skin property returns empty string
                string calendarSkin = RadCalendar1.Skin != "" ? RadCalendar1.Skin : "Default";
                string otherMonthCssClass = String.Format("otherMonth_{0}", calendarSkin);

                // disable the selection for the specific day
                RadCalendarDay calendarDay = new RadCalendarDay();
                calendarDay.Date = transactionDate; //the date which has to be preselected
                calendarDay.IsSelectable = false;
                calendarDay.ItemStyle.CssClass = otherMonthCssClass;
                RadCalendar1.SpecialDays.Add(calendarDay);

                //Pre select the transaction date selected in the entry screen
                RadCalendar1.SelectedDates.Add(new RadDate(transactionDate));


Problem here is :

When pop up opens, actual 'transactiondate' is preselected which is fine. If I change the month, select different dates and come back to the month having preselected date, then I see that it is not preselected. Its selection is still disabled but it is not highlighted. 

If I put just this code    
                   RadCalendar1.SelectedDates.Add(new RadDate(transactionDate)); 
and remove the code where the date is disabled,  then everything works fine.

I think bcz of the code which is disabling the specific date, preselection is not presisting.

Any help pls,
Thanks,
AV

0
Iana Tsolova
Telerik team
answered on 28 Sep 2011, 09:41 AM
Hi Pams,

Try using the code where you add the special day together with AutoPostBack set to true for the calendar. If postback is not enabled for the RadCalendar, then you should handle its client-side DayRender event and re-add the special day as selected after month navigation. Find more about the calendar DayRender event here.
Another option is to add the date as selected only, with adding it to the special day collection and disable its selection either by canceling the OnDateSelecting event or as illustrated in this code library.

Additionally, you can try the approach used in the sample here.

Regards,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Pams
Top achievements
Rank 1
answered on 05 Oct 2011, 07:34 PM
Hello,
Thanks for your reply. 
I used AutoPostBack=true and removed the disabling code in page load. I am using onDateSelectingEvent where i am checking my transactionDate and not allowing to unselect.
That is working for me.
Thanks,
AV
Tags
Calendar
Asked by
Pams
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Pams
Top achievements
Rank 1
Share this question
or