Advanced edit form issue in SP2010 web part + ajaxmanager

9 posts, 0 answers
  1. Jonathan Simmons
    Jonathan Simmons avatar
    107 posts
    Member since:
    Jun 2005

    Posted 26 May 2014 Link to this post

    Hello, I have created a web part using a RadScheduler and have followed all the instructions to add RadAjaxManager support for the scheduler.

    This all works fine but I have noticed an issue with the advanced edit/insert form.

    The scheduler is configured to use the advanced form (StartInsertingInAdvancedForm) and when I double click a time slot, the advanced editor opens up.

    However, if a user forgets to enter text in the Subject textbox and clicks Save, the Subject textbox border changes to red to prompt the user to enter the subject text. But once this has happened, clicking on Save, Cancel or the X to close the advanced edit form has no effect at all. Nothing happens. And due to the modal nature of the advanced edit form, the only way to go back to the scheduler itself is to refresh the page, losing any changes the user has made.

    I have tested this without the AjaxManager and this issue does not appear - so must be to do with ajaxifying the scheduler.

    Any ideas why this might happen?

    Thanks,
    Jonathan
  2. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 29 May 2014 Link to this post

    Hi Jonathan,

    The described behavior sound quite unusual. I have tested it at our side but could not observe it locally. Would you please send us the exact mark up of RadScheduler used and the code connected with RadAjaxManager that you use so we could inspect it locally and be more helpful with a possible solution?

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonathan Simmons
    Jonathan Simmons avatar
    107 posts
    Member since:
    Jun 2005

    Posted 29 May 2014 in reply to Plamen Link to this post

    Hello Plamen, Here is the aspx and cs. Hopefully you will be able to spot where I have gone wrong!

     
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CCalendar.ascx.cs" Inherits="CommsCalendar.CCalendar.CCalendar" %>
    <%@ Register assembly="Telerik.Web.UI, Version=2014.1.403.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %>
     
    <style>
        .rsHeader
        {
            z-index:50 !important;
        }
    </style>
     
    <telerik:RadScheduler ID="RadScheduler1" runat="server" DataDescriptionField="Location" DataEndField="End" DataKeyField="ID" DataStartField="Start" DataSubjectField="Location" FirstDayOfWeek="Monday" LastDayOfWeek="Friday" HoursPanelTimeFormat="H:mm" OnAppointmentInsert="RadScheduler1_AppointmentInsert" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" SelectedView="WeekView" Skin="Office2010Blue" TimeZoneID="GMT Standard Time" OnAppointmentDataBound="RadScheduler1_AppointmentDataBound" EnableResourceEditing="False" OnAppointmentDelete="RadScheduler1_AppointmentDelete" Culture="en-GB" Width="100%" WorkDayEndTime="18:00:00" StartInsertingInAdvancedForm="True" Height="100%" AllowDelete="True" OnClientTimeSlotClick="OnTimeSlotClick" OnClientAppointmentDoubleClick="OnCLientAppointmentDoubleClick" OnClientAppointmentEditing="OnClientAppointmentEditing">
    <ExportSettings>
    <Pdf PageTopMargin="1in" PageBottomMargin="1in" PageLeftMargin="1in" PageRightMargin="1in"></Pdf>
    </ExportSettings>
        <AdvancedForm Modal="True" EnableResourceEditing="False" />
        <TimelineView UserSelectable="False" ColumnHeaderDateFormat="ddd-MM" />
        <WeekView ColumnHeaderDateFormat="ddd dd" HeaderDateFormat="ddd dd MMM" />
        <DayView UserSelectable="False" />
        <MonthView UserSelectable="False" />
        <AppointmentContextMenuSettings EnableDefault="True" />
        <TimeSlotContextMenuSettings EnableDefault="True" />
        <InlineEditTemplate>
             
        </InlineEditTemplate>
    </telerik:RadScheduler>
    <p>(Right-click calendar to create/edit entry)</p>
    <telerik:RadAjaxLoadingPanel ID="lp1" runat="server" Skin="Web20"></telerik:RadAjaxLoadingPanel>
     
     
    <%--<script type="text/javascript" src="/_layouts/MicrosoftAjax.js" ></script>
    <script type="text/javascript" src="/_layouts/SP.debug.js"></script>--%>
     
    <script type="text/javascript">
        var check = false;
        function OnTimeSlotClick(sender, args)
        {
            //sender.get_timeSlotContextMenus()[0].show(args.get_domEvent());
        }
     
        //Prevent Edit when appointment is double-clicked
        function OnCLientAppointmentDoubleClick(sender, args)
        {
            //check = true;
        }
        function OnClientAppointmentEditing(sender, args)
        {
            //args.set_cancel(check);
        }
     
    </script>

    And the code behind:

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Web.UI;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using System.Data;
    using Microsoft.SharePoint.Linq;
    using System.Collections.Generic;
    using System.Linq;
    using Telerik.Web.UI;
    using System.Diagnostics;
     
    namespace CommsCalendar.CCalendar
    {
        [ToolboxItemAttribute(false)]
        public partial class CCalendar : WebPart
        {
            // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
            // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
            // for production. Because the SecurityPermission attribute bypasses the security check for callers of
            // your constructor, it's not recommended for production purposes.
            // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
            public CCalendar()
            {
            }
     
            RadAjaxManager _ajaxManager;
            bool _userHasPermission = false;
     
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                InitializeControl();
     
                _userHasPermission = CheckUserPermission();
                RadScheduler1.TimeSlotContextMenus.Add(BuildTimeSlotContextMenu());        
                SetUpAjaxManagerOnPage();
            }
     
            protected void SetUpAjaxManagerOnPage()
            {
                RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
                if (currentAjaxManager == null)
                {
                    Page.Form.Controls.AddAt(0, AjaxManager);
                    Page.Items.Add(typeof(RadAjaxManager), AjaxManager);
                }
            }
     
            protected virtual RadAjaxManager AjaxManager
            {
                get
                {
                    if (_ajaxManager == null)
                    {
                        _ajaxManager = RadAjaxManager.GetCurrent(Page);
                        if (_ajaxManager == null)
                        {
                            _ajaxManager = new RadAjaxManager() { ID = "RadAjaxManager1" };
                        }
                    }
                    return _ajaxManager;
                }
            }
     
            protected override void CreateChildControls()
            {
            }
     
            protected override void OnLoad(EventArgs e)
            {
               base.OnLoad(e);
               RadScheduler scheduler = this.FindControl("RadScheduler1") as RadScheduler;
     
               RadAjaxManager _manager = RadAjaxManager.GetCurrent(Page);
               RadAjaxLoadingPanel lp = (RadAjaxLoadingPanel)FindControl("lp1");
     
               _manager.AjaxSettings.AddAjaxSetting(scheduler, scheduler, lp);
     
            }
     
            protected void Page_Load(object sender, EventArgs e)
            {                      
                if (!Page.IsPostBack)
                {
                    LoadSchedulerData(); 
                }
            }
     
            protected RadSchedulerContextMenu BuildTimeSlotContextMenu()
            {
                RadSchedulerContextMenu cxt = new RadSchedulerContextMenu();
                cxt.ID = "MyTimeSlotContextMenu";
                cxt.Items.Add(new RadMenuItem() { Text = "Add New Appointment", Value = "CommandAddAppointment", Enabled = _userHasPermission });
                cxt.Items.Add(new RadMenuItem() { Text = "Goto Today", Value = "CommandGoToToday" });
                cxt.Items.Add(new RadMenuItem() { Text = "Show 24 hours...", Value = "CommandShow24Hours" });
                return cxt;
            }
     
            protected RadSchedulerContextMenu BuildAppointmentContextMenu()
            {
                //Not used as Radscheduler AllowEdit and AllowDelete overrides Enabled settings at this level
                RadSchedulerContextMenu cxtAppContext = new RadSchedulerContextMenu();
                cxtAppContext.ID = "MyAppointmentContextMenu";
                cxtAppContext.Items.Add(new RadMenuItem() { Text = "MyEdit", Value = "CommandShow24Hours", Enabled = _userHasPermission });
                cxtAppContext.Items.Add(new RadMenuItem() { Text = "MyDelete", Value = "CommandDelete", Enabled = _userHasPermission });
                return cxtAppContext;
            }
     
            private bool CheckUserPermission()
            {
                bool userHasPermission = false;
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                using (SPWeb web = site.OpenWeb())
                {
                    SPUser thisUser = SPContext.Current.Web.CurrentUser;
                    SPList appts = web.Lists["Calendar"];
                    userHasPermission = appts.DoesUserHavePermissions(thisUser, SPBasePermissions.AddListItems);
                }
                return userHasPermission;
            }
     
            protected void LoadSchedulerData()
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Calendar"];
                    SPListItemCollection apptCollection = list.GetItems(new SPQuery()
                        {
                            //Don't bother loading events more than 7 days old
                            Query = "<Where><Geq><FieldRef Name='EventDate'/><Value Type='DateTime'><Today OffsetDays='-7'/></Value></Geq></Where>"
                        });
     
                    RadScheduler1.DataStartField = "EventDate";
                    RadScheduler1.DataEndField = "EndDate";
                    RadScheduler1.DataKeyField = "ID";
                    RadScheduler1.DataSubjectField = "Title";
                    RadScheduler1.DataDescriptionField = "Description";
     
                    RadScheduler1.DataSource = apptCollection.GetDataTable(); 
                    RadScheduler1.DataBind();
                }
            }
     
            protected void RadScheduler1_AppointmentUpdate(object sender, Telerik.Web.UI.AppointmentUpdateEventArgs e)
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                using (SPWeb web = site.OpenWeb())
                {
                    SPList calList = web.Lists["Calendar"];
                    SPListItem appointment = calList.GetItemById((int)e.ModifiedAppointment.ID);
                    if (appointment != null)
                    {
                        appointment["EventDate"] = e.ModifiedAppointment.Start;
                        appointment["EndDate"] = e.ModifiedAppointment.End;
                        appointment["Title"] = e.ModifiedAppointment.Subject;
                        appointment["Description"] = e.ModifiedAppointment.Description;
                        appointment.Update();
                    }
                }
                LoadSchedulerData();
            }
     
            protected void RadScheduler1_AppointmentInsert(object sender, Telerik.Web.UI.AppointmentInsertEventArgs e)
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                using (SPWeb web = site.OpenWeb())
                {
                    SPList calList = web.Lists["Calendar"];
                    SPListItem appointment = calList.Items.Add();
                    appointment["Title"] = e.Appointment.Subject;
                    appointment["EventDate"] = e.Appointment.Start;
                    appointment["EndDate"] = e.Appointment.End;
                    appointment["Description"] = e.Appointment.Description;
                    appointment.Update();
                }
                LoadSchedulerData();
            }
     
            protected void RadScheduler1_AppointmentDelete(object sender, AppointmentDeleteEventArgs e)
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["Calendar"];
                        list.Items.DeleteItemById((int)e.Appointment.ID);
                    }
                }
            }     
             
            protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
            {
                //We can set Edit/Delete permission here which will override the base settings of the RadScheduler
                e.Appointment.AllowEdit = _userHasPermission;
                e.Appointment.AllowDelete = _userHasPermission;
                e.Appointment.BackColor = Color.FromArgb(255, 51, 108, 171);
                e.Appointment.ForeColor = Color.FromArgb(255, 255, 255);
            }
     
        }
    }

    Regards,
    Jonathan
  5. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 04 Jun 2014 Link to this post

    Hello Jonathan,
     
    I have inspected the scenario but could not replicate the unusual behavior. I am attaching the sample Web part that worked correctly at my side in a similar scenario. Please review it and let me know if you still reproduce the issue with it. Please let us know if you observe any particular javascript errors in the console when you replicate the issue.

    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.

     
  6. Jonathan Simmons
    Jonathan Simmons avatar
    107 posts
    Member since:
    Jun 2005

    Posted 04 Jun 2014 in reply to Plamen Link to this post

    Hi Plamen, thanks for your reply. Unfortunately I still have the same issue. To reproduce this:
    - StartInsertingInAdvancedForm="True"
    - Add new appointment
    - Click 'Save' without entering a subject
    - Click Cancel (or try to close modal form)
    Advanced Edit Form will not close.

    Interestingly, looking at the following javascript:

    function Sys$WebForms$PageRequestManager$_onFormSubmit(evt) {
        var continueSubmit = true;
        var isCrossPost = this._isCrossPost;
        this._isCrossPost = false;
        var i, l;
        if (this._onsubmit) {
            continueSubmit = this._onsubmit();
        }
        if (continueSubmit) {
            for (i = 0, l = this._onSubmitStatements.length; i < l; i++) {
                if (!this._onSubmitStatements[i]()) {
                    continueSubmit = false;
                    break;
                }
            }
        }
        if (!continueSubmit) {
            if (evt) {
                evt.preventDefault();
            }
            return;
        }
    more function code...

    If I open the Advanced Edit form and just click Cancel, then continueSubmit is true, but if I click Save with no text in Subject and then click Cancel, continueSubmit is false (set from this.onsubmit()).

    Using Telerik.Web.UI 2014.1.403.35
    SharePoint 2010 14.0.6029.1000
    Visual Studio 2013 Update 2

    Regards,
    Jonathan
      



  7. Jonathan Simmons
    Jonathan Simmons avatar
    107 posts
    Member since:
    Jun 2005

    Posted 04 Jun 2014 in reply to Jonathan Simmons Link to this post

    Just noticed that this behaviour is exactly the same when using SPRadSchedulerWebPart.

  8. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 09 Jun 2014 Link to this post

    Hi Jonathan,

    Thank you for elaborating the issue and the steps to reproduce it. I have tested once again both the custom WebPart that I sent you and our SPRadSchedulerWebPart with the version of our controls that you pointed but could not observe the issue. Here is the video of my test. Please review it and let me know if I am not testing properly or I have to add or do something else in order to replicate the issue.

    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.

     
  9. Jonathan Simmons
    Jonathan Simmons avatar
    107 posts
    Member since:
    Jun 2005

    Posted 09 Jun 2014 in reply to Plamen Link to this post

    Hello Plamen, thanks for your help with this.

    Looking at the code you supplied, it looks like this was built in VS2010 where the way a visual web part is created is different to that in VS 2013. The visual web part templates are different.

    This video describes the difference: Using the Visual Web Part Template in Visual Studio 2012

    In VS 2013 using the visual web part template I get the problems I have described. Recreating the project in VS 2010 using the visual web part template and exactly the same code, I don't get these issues.

    The solution: use the VS 2010 way to build the web part (or perhaps the VS 2013 SharePoint User Control (Farm Solution only) and then wire everything up myself?).

    Anyway, thanks for your help with this issue. 
    Jonathan


  10. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 10 Jun 2014 Link to this post

    Hello,

    Thank you for explaining the solution for the issue and for your concern with RadControls.

    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