Click on the same date

4 posts, 0 answers
  1. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 24 Sep 2013 Link to this post

    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"
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Sep 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 25 Sep 2013 Link to this post

    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 ...
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Sep 2013 Link to this post

    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.
Back to Top