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

Click on the same date

3 Answers 30 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 24 Sep 2013, 10:49 AM
Click on the same date two times gives NULL value second time.
How do I get away with it, so I get the same value even if I click the same date more than once?

Try: http://demos.telerik.com/aspnet-ajax/calendar/examples/programming/serversideevents/defaultcs.aspx
Changed Date to: "9/30/2013 12:00:00 AM"
Changed Date to: "none"

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 25 Sep 2013, 07:14 AM
Hi Kjell,

When you again click on a selected date in the RadCalendar, that particular date gets unselected and this is how the RadCalendar works. Suppose you don't want the selected date to get unselected by clicking that again, you can try the following code.

ASPX:
<telerik:RadCalendar ID="RadCalendar1" AutoPostBack="true" runat="server" OnSelectionChanged="RadCalendar1_SelectionChanged"
    ClientEvents-OnDateSelecting="OnDateSelecting">
</telerik:RadCalendar>
<asp:Label ID="Label1" runat="server"></asp:Label>

JavaScript:
<script type="text/javascript">
    function OnDateSelecting(sender, args) {
        if (args.get_isSelecting() == false) {
            args.set_cancel(true);
        }
    }
</script>

C#:
protected void RadCalendar1_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
{
    string date = e.SelectedDates.Count - 1 >= 0 ? e.SelectedDates[e.SelectedDates.Count - 1].Date.ToString() : "none";
    Label1.Text="Changed Date to: \"" + date + "\"";
}

Thanks,
Shinu.
0
Kjell
Top achievements
Rank 1
answered on 25 Sep 2013, 09:37 AM
Still a problem, when I click the second time, AutoPostBack not working.

I have two calendars on one page and the visitor to see activity again as he had previously clicked on, he must click on another date first and then click the current date.
I collect activity from the database ...
0
Shinu
Top achievements
Rank 1
answered on 26 Sep 2013, 05:48 AM
Hi Kjell,

Please try the following updated code which works as expected.

ASPX:
<telerik:RadCalendar ID="RadCalendar1" AutoPostBack="true" runat="server" OnSelectionChanged="RadCalendar1_SelectionChanged"
    ClientEvents-OnDateSelected="OnDateSelected">
</telerik:RadCalendar>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>

JavaScript:
<script type="text/javascript">
    function OnDateSelected(sender, args) {
        if (args.get_renderDay().IsSelected == false) {
            args.get_renderDay().Select();
        }
    }
</script>

C#:
protected void RadCalendar1_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
{
    string date = e.SelectedDates.Count - 1 >= 0 ? e.SelectedDates[e.SelectedDates.Count - 1].Date.ToString("dd-MM-yyyy") : "none";
    Label1.Text = "Changed Date to: \"" + date + "\"";
}

Thanks,
Shinu.
Tags
Calendar
Asked by
Kjell
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Kjell
Top achievements
Rank 1
Share this question
or