OnClientAppointmentMoveEnd is not working

2 posts, 0 answers
  1. Allen
    Allen avatar
    111 posts
    Member since:
    Apr 2012

    Posted 19 Nov 2012 Link to this post

    I'm try to change the start time of an appointment when it call the function "OnClientAppointmentMoveEnd", but it will not change the start time.
    Here is my codes:

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="RadSchedulerAdvancedForm.aspx.vb"
     Inherits="RadSchedulerAdvancedForm" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="scheduler" TagName="AdvancedForm" Src="AdvancedForm.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <style type="text/css">
      .RadScheduler .rsAdvancedEdit .RadColorPicker label
      {
       text-align: left;
       display: block;
       padding: 0;
      }
     </style>
     <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body class="BODY">
     <form id="Form1" method="post" runat="server">
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
      <Scripts>
       <asp:ScriptReference Path="~/ObjectDataSource/AdvancedForm.js" />
       <%--Needed for JavaScript IntelliSense in VS2010--%>
       <%--For VS2008 replace RadScriptManager with ScriptManager--%>
       <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
      </Scripts>
     </telerik:RadScriptManager>
     <script type="text/javascript"> 
      //<![CDATA[
        
         function ChangeStartTime() {
         }
         function ClientAppointmentEditing(sender, eventArgs) {
         }

         function OnClientAppointmentMoveEnd(sender, eventArgs) {
                         var newStartTimeAvailable = new Date('Wed Nov 20 11:00:00 EST 2012');
                         eventArgs.get_appointment().set_start(newStartTimeAvailable);
                         sender.updateAppointment(eventArgs.get_appointment());
                     }

      var schedulerTemplates = {};

      function schedulerFormCreated(scheduler, eventArgs) {
       // Create a client-side object only for the advanced templates
       var mode = eventArgs.get_mode();
       if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
         mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
        // Initialize the client-side object for the advanced form
        var formElement = eventArgs.get_formElement();
        var templateKey = scheduler.get_id() + "_" + mode;
        var advancedTemplate = schedulerTemplates[templateKey];
        if (!advancedTemplate) {
         // Initialize the template for this RadScheduler instance
         // and cache it in the schedulerTemplates dictionary
         var schedulerElement = scheduler.get_element();
         var isModal = scheduler.get_advancedFormSettings().modal;
         advancedTemplate = new window.SchedulerAdvancedTemplate(schedulerElement, formElement, isModal);
         advancedTemplate.initialize();

         schedulerTemplates[templateKey] = advancedTemplate;

         // Remove the template object from the dictionary on dispose.
         scheduler.add_disposing(function () {
          schedulerTemplates[templateKey] = null;
         });
        }

        // Are we using Web Service data binding?
        if (!scheduler.get_webServiceSettings().get_isEmpty()) {
         // Populate the form with the appointment data
         var apt = eventArgs.get_appointment();
         var isInsert = mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert;
         advancedTemplate.populate(apt, isInsert);
        }
       }
      }
       
      //]]>
     </script>
     <div class="exampleContainer">
      <telerik:RadScheduler runat="server" ID="RadScheduler1" DataEndField="End" Reminders-Enabled="true"
       AppointmentStyleMode="Default" DataKeyField="ID"
       
       DataStartField="Start" CustomAttributeNames="AppointmentColor"
       OnClientFormCreated="schedulerFormCreated" DataSubjectField="Subject" OnAppointmentDataBound="RadScheduler1_AppointmentDataBound"
       
                onclientappointmentmoveend="OnClientAppointmentMoveEnd" Height="640px"
                OverflowBehavior="Expand" AllowDelete="False" SelectedView="WeekView"
                                                                    Localization-ContextMenuEdit="AAA"
                                                                    onclientappointmentediting="ClientAppointmentEditing"
                                                                   
                >
       <AppointmentTemplate>
                     <div class="rsAptSubject">
                         <%# Eval("Subject") %>
                     </div>
                     <%# Eval("Description") %>
                 </AppointmentTemplate>
                 <AdvancedEditTemplate>
                     <scheduler:AdvancedForm runat="server" ID="AdvancedEditForm1" Mode="Edit"
                         Subject='<%# Bind("Subject") %>'
                         Description='<%# Bind("Description") %>'
                         Start='<%# Bind("Start") %>'
                         End='<%# Bind("End") %>'
                         RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                            Reminder='<%# Bind("Reminder") %>'
                         AppointmentColor='<%# Bind("AppointmentColor") %>'
                             />
                             <%--TimeZoneID='<%# Bind("TimeZoneID") %>'--%>
                             <%--UserID='<%# Bind("User") %>'--%>
                             <%--RoomID='<%# Bind("Room") %>'--%>
                 </AdvancedEditTemplate>
                 <AdvancedInsertTemplate>
                     <scheduler:AdvancedForm runat="server" ID="AdvancedInsertForm1" Mode="Insert"
                         Subject='<%# Bind("Subject") %>'
                         Start='<%# Bind("Start") %>'
                         End='<%# Bind("End") %>'
                         Description='<%# Bind("Description") %>'
                         RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                            Reminder='<%# Bind("Reminder") %>'
                         AppointmentColor='<%# Bind("AppointmentColor") %>'
                             />
                             <%--TimeZoneID='<%# Bind("TimeZoneID") %>'--%>
                             <%--UserID='<%# Bind("User") %>'--%>
                             <%--RoomID='<%# Bind("Room") %>'--%>
                 </AdvancedInsertTemplate>
               
                                                            <AdvancedForm Modal="True" Width="400px" EnableTimeZonesEditing="True" />

                                                            <ResourceTypes>
    <%--                                                        <telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="USERID"
                                                            KeyField="ID" Name="Users" TextField="USERNAME" />--%>
                                                            </ResourceTypes>
                                                            <TimelineView UserSelectable="False" />
                                                            <WeekView DayEndTime="23:59:59" ColumnHeaderDateFormat="dddd, d"
                                                                GroupingDirection="Vertical" />
                                                            <Localization AdvancedEditAppointment="Edit" AdvancedNewAppointment="New"
                                                                AllDay="Range" />
                                                                
                                                            <MonthView FirstDayHeaderDateFormat="MMMM dd" ColumnHeaderDateFormat="MMMM dddd"
                                                                HeaderDateFormat="MMMM, yyyy" />
                                                        </telerik:RadScheduler>
      <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="AllUsers"
       TypeName="UserList"></asp:ObjectDataSource>
      <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteAppointment"
       InsertMethod="InsertAppointment" SelectMethod="AllData" TypeName="AppointmentList"
       UpdateMethod="UpdateAppointment">
       <DeleteParameters>
        <asp:Parameter Name="ID" Type="String" />
       </DeleteParameters>
       <InsertParameters>
        <asp:Parameter Name="Subject" Type="String" />
        <asp:Parameter Name="AppointmentColor" Type="String" />
        <asp:Parameter Name="Start" Type="DateTime" />
        <asp:Parameter Name="End" Type="DateTime" />
        <asp:Parameter Name="Reminder" Type="String" />
        <asp:Parameter Name="UserID" Type="Int32" />
        <asp:Parameter Name="TimeZoneID" Type="String" />
        <asp:Parameter Name="RecurrenceRule" Type="String" />
        <asp:Parameter Name="RecurrenceParentID" Type="String" />
       </InsertParameters>
       <UpdateParameters>
        <asp:Parameter Name="ID" Type="String" />
        <asp:Parameter Name="Subject" Type="String" />
        <asp:Parameter Name="AppointmentColor" Type="String" />
        <asp:Parameter Name="Start" Type="DateTime" />
        <asp:Parameter Name="End" Type="DateTime" />
        <asp:Parameter Name="RecurrenceRule" Type="String" />
        <asp:Parameter Name="RecurrenceParentID" Type="String" />
        <asp:Parameter Name="TimeZoneID" Type="String" />
        <asp:Parameter Name="Reminder" Type="String" />
        <asp:Parameter Name="UserID" Type="Int32" />
       </UpdateParameters>
      </asp:ObjectDataSource>
     </div>
     </form>
    </body>
    </html>


  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2035 posts

    Posted 22 Nov 2012 Link to this post

    Hello Allen,

    Please add to your markup code DataSourceID for your RadScheduler control. I your case that would be:

    <telerik:RadScheduler runat="server" ID="RadScheduler1" ....  DataSourceID="ObjectDataSource1">
    .....
     </telerik:RadScheduler>

    The reason for the described issue was that there was no ID value set to the appointments and therefore the updateAppointment() method throws exception.
    Please keep in mind that appointment start time needs to be before the appointment end time. This could require to edit your OnClientAppointmentMoveEnd() method.


    Regards,
    Boyan Dimitrov
    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.
Back to Top