When does RadScheduler SelectedDate get set?

10 posts, 1 answers
  1. Robert Helm
    Robert Helm avatar
    54 posts
    Member since:
    Feb 2009

    Posted 10 Feb 2012 Link to this post

    I've got a RadScheduler and after postback, the SelectedDate gets set somewhere, somehow, back to the current date. The problem is, if the user navigates to another month than the current one, then causes a postback, instead of staying on the current month, it goes back to the initial SelectedDate (today's date).

    Thanks for any feedback.

    -Bob
  2. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 15 Feb 2012 Link to this post

    Hi Robert,

     I could not reproduce this behavior in none of our demos. Here you can see a video of the my test.

    Can you post the code that is connected to the RadScheduler functionality in your scenario so we can reproduce the issue locally?

    Kind regards,
    Plamen Zdravkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert Helm
    Robert Helm avatar
    54 posts
    Member since:
    Feb 2009

    Posted 15 Feb 2012 Link to this post

    Thank you for the response, Plamen. Below is the code I used, stripping out some code to keep it simple, using "...comments..." instead.

    Basically, my javascript method calls a static page method which calls a class to do the work and then do a postback of the page. At that point, in the ASP.NET Page_Load, the RadScheduler.SelectedDate is still OK, on the proper date that the user navigated to. But when I call a method to rebind my data to the RadScheduler, the RadScheduler.SelectedDate has been reset to today. So the issue seems to be in between the last 2 methods below, PageLoad() and BindScheduler(). I noted those comments with *****.




    <telerik:RadScheduler ID="RadScheduler" runat="server" TimeZoneOffset="00:00:00" SelectedView="MonthView"
            TimelineView-UserSelectable="false" OverflowBehavior="Scroll"
            DataKeyField="AppointmentID"
            DataStartField="AppointmentStartTime"
            DataEndField="AppointmentEndTime"
            CustomAttributeNames="...various attributes..."
            StartEditingInAdvancedForm="false"
            StartInsertingInAdvancedForm="False"
            EnableRecurrenceSupport="false"
            AdvancedForm-EnableCustomAttributeEditing="true"               
            AdvancedForm-Enabled="false"
            OnAppointmentDataBound="RadScheduler_AppointmentDataBound"
            OnFormCreating="RadScheduler_FormCreating"              
            OnNavigationCommand="RadScheduler_NavigationCommand"
            OnNavigationComplete="RadScheduler_NavigationComplete"
            OnClientAppointmentContextMenuItemClicked="OnClientAppointmentContextMenuItemClicked"
            OnAppointmentCreated="RadScheduler_AppointmentCreated"                                         
            OnClientAppointmentContextMenu="OnClientAppointmentContextMenuHandler"
            OnClientAppointmentMoveEnd="OnClientMoveEnd" >
        <AdvancedForm EnableCustomAttributeEditing="True" Enabled="False" />
        <MonthView VisibleAppointmentsPerDay="10" ReadOnly="true" />
        <TimelineView UserSelectable="False" />
        <TimeSlotContextMenuSettings EnableDefault="false" />
        ...set up appointment templates, menu, etc...
    </telerik:RadScheduler>

    <script type="text/javascript">

        function OnClientAppointmentContextMenuHandler(sender, eventArgs) {
            eventArgs.get_domEvent().preventDefault();
        }

        function OnClientMoveEnd(sender, eventArgs) {
            ...set up local variables pulled from eventArgs, etc...
            validateMove(Appointmentid, NewDate, NewStart, NewEnd);
        }

        function validateMove(id, NewDate, NewStart, NewEnd) {
            PageMethods.ValidateMove(id, NewDate, NewStart, NewEnd, onValidateMoveSuccess);
        }

        function onValidateMoveSuccess(result, context, methodName) {
            if (result != "") {
                ...set up local variables W,A,B,X,etc...
                var resp = confirm(result);
                if (resp) {
                    __doPostBack('__Page', 'REFRESH|W|A|B|X|')
                }   
            }
        }

    </script>

    ///C# Code behind
    [System.Web.Services.WebMethod]
    public static string ValidateMove(...arguments passed in...)
    {
        //calls a static method on a class to do server work, etc
        return HomePageHelper.RescheduleAppointment(...arguments passed in and out...);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.GetCurrent(this.Page).EnablePageMethods = true; //38095
                  
        if (!IsPostBack) {   
            BindScheduler();
        }
        else {

            string eventArg = Request["__EVENTARGUMENT"];
            if (eventArg.Contains("REFRESH"))
            {
                if (eventArg.Split('|')[1].Contains("W"))    //Scheduling drag/drop dialog result
                {
                    return HomePageHelper.RescheduleAppointment(...arguments passed in and out...);
                }

                ***** At this point, the RadScheduler.SelectedDate is OK, meaning it is still
                set to whatver month/day the user had navigated to *****

                BindScheduler();

            }       
        }
    }    
                   
    private void BindScheduler()
    {
        ***** By the time I get here, the RadScheduler.SelectedDate has already been
        set back to the current day ***** 
     
        ApptList = FillList(...arguments passed in, etc...) //ApptList is a list of appointments    

        RadScheduler.DataSource = ApptList;
    }

           
           
           
           
           
           
           
           
           
           
           
           
           

  5. Robert Helm
    Robert Helm avatar
    54 posts
    Member since:
    Feb 2009

    Posted 15 Feb 2012 Link to this post

    Also, I may have a workaround that I am still testing. That's simply setting the RadScheduler.SelectedDate = RadScheduler.SelectedDate in the Page_Load() right before I call BindScheduler() to rebind the data. I'm still testing that though.
  6. Answer
    Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 20 Feb 2012 Link to this post

    Hello Robert,

     
    I will recommend you to refer to our Bind To List demo, where the a similar scenario is described and the selected date is working properly. 

    Another way to handle this issue is to pass the selected date in the BindScheduler method as a parameter and reset it inside it once again.

    Hope this will be helpful.

    Regards,
    Plamen Zdravkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Robert Helm
    Robert Helm avatar
    54 posts
    Member since:
    Feb 2009

    Posted 27 Feb 2012 Link to this post

    Thanks Plamen. Passing the selected date into the BindScheduler method works fine.
     
  8. Sandy
    Sandy avatar
    26 posts
    Member since:
    Mar 2012

    Posted 11 Oct 2013 Link to this post

    Hi,

    I am getting the current date into Appscheduler.slecteddate.

    please help me.
    below is my Code.


    public void AppScheduler_AppointmentClick(object sender, SchedulerEventArgs e)
            {
                

                DateTime SelectedDate = AppScheduler.SelectedDate;
                IBopAppointmentService dt = ServiceFactory.Create<BopAppointmentService>();
                List<BOPAppointmentVWDTO> lstBopAppointment = dt.GetAppointmentsByDate(SelectedDate).ToList();
    }
  9. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 14 Oct 2013 Link to this post

    Hi Sandy,

     
    I have tested the provided code and it worked as expected at my side. I will recommend you to check whether you are setting the SelectedDate somewhere else in your code behind that may affect the result in the click event.

    Regards,
    Plamen
    Telerik
    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 the blog feed now.
  10. Venkatesh
    Venkatesh avatar
    1 posts
    Member since:
    Sep 2014

    Posted 02 Sep 2014 Link to this post

    Hi,

    Ive a similar issue. Below is my code

    DateTime t = RadScheduler1.SelectedDate;
    DateTime t1 = RadScheduler1.SelectedDate.AddDays(30);
  11. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 05 Sep 2014 Link to this post

    Hello,

    It is not quite clear what you are trying to achieve with the code provided but you can get the Selected Date of RadScheduler on page load for example as in the code below:
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(RadScheduler1.SelectedDate);
        RadScheduler1.SelectedDate = DateTime.Today;
    }


    Regards,
    Plamen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017