No error message with DurationValidator in AdvancedForm

3 posts, 0 answers
  1. CLAUDE LLOP
    CLAUDE LLOP avatar
    10 posts
    Member since:
    Mar 2008

    Posted 19 Apr 2012 Link to this post

    Hi,

    In my scheduler, in AdvancedForm Edit mode: when I compare 2 dates (StartDate, EndDate, StartTime, EndTime) and the StartDate is greater than the EndDate I catch an exception.
    But the defined message doesn't appear after submitting and all textboxes are empty with a warning icon (Enclosed screenshot of actual result).
    It's the same issue with StartTime and EndTime.
    How can I display my warning message to inform my user which date is wrong ?
    Here is the code :
    ------------------------------------
    AdvancedFormCS.ascx :
    <%@ Control Language="C#" AutoEventWireup="true"
        Inherits="SchedulerTemplatesCS.AdvancedForm" Codebehind="AdvancedFormCS.ascx.cs" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <div class="rsAdvancedEdit rsAdvancedModal" style="positionrelative">
        <div class="rsModalBgTopLeft">
        </div>
        <div class="rsModalBgTopRight">
        </div>
        <div class="rsModalBgBottomLeft">
        </div>
        <div class="rsModalBgBottomRight">
        </div>
        <%-- Title bar. --%>
        <div class="rsAdvTitle">
            <%-- The rsAdvInnerTitle element is used as a drag handle when the form is modal. --%>
            <h1 class="rsAdvInnerTitle">
                <%= (this.Mode.ToString() == "Edit") ? Owner.Localization.AdvancedEditAppointment : Owner.Localization.AdvancedNewAppointment %></h1>
            <asp:LinkButton runat="server" ID="AdvancedEditCloseButton" CssClass="rsAdvEditClose"
                CommandName="Cancel" CausesValidation="false" ToolTip='<%# Owner.Localization.AdvancedClose %>'>
    			<%= Owner.Localization.AdvancedClose %>
            </asp:LinkButton>
        </div>
        <div class="rsAdvContentWrapper">
            <%-- Scroll container - when the form height exceeds MaximumHeight scrollbars will appear on this element--%>
            <div class="rsAdvOptionsScroll">
                <asp:Panel runat="server" ID="AdvancedEditOptionsPanel" CssClass="rsAdvOptions">
                    <asp:Panel runat="server" ID="BasicControlsPanel" CssClass="rsAdvBasicControls">
                        <asp:Label runat="server" ID="SubjectText" Width="100%" Label='<%# Owner.Localization.AdvancedSubject + ":" %>' EnableSingleInputRendering="false" />
                        <ul class="rsTimePickers">
                            <li class="rsTimePick">
                                <label for='<%= StartDate.ClientID %>_dateInput_text'>
                                    <%= Owner.Localization.AdvancedFrom %></label><%--
    							    Leaving a newline here will affect the layout, so we use a comment instead.
                                    --%><telerik:RadDatePicker runat="server" ID="StartDate" CssClass="rsAdvDatePicker" 
                                        Width="83px" SharedCalendarID="SharedCalendar" Skin='<%# Owner.Skin %>' Culture='<%# Owner.Culture %>' >
                                        <DatePopupButton Visible="False"/>
                                        <DateInput ID="DateInput2" runat="server" DateFormat='<%# Owner.AdvancedForm.DateFormat %>'
                                            EmptyMessageStyle-CssClass="riError" EmptyMessage=" " EnableSingleInputRendering="false"/>
                                    </telerik:RadDatePicker>
                                <%--
    							
                                --%><telerik:RadTimePicker runat="server" ID="StartTime" CssClass="rsAdvTimePicker"
                                    Width="65px" Skin='<%# Owner.Skin %>' Culture='<%# Owner.Culture %>'>
                                    <TimeView ShowHeader="true" HeaderText="Sélectionner une heure de début"  runat="server" Skin='<%# Owner.Skin %>' ID="TimeViewStart" />
                                    <DateInput ID="DateInput3" runat="server" EmptyMessageStyle-CssClass="riError" EmptyMessage=" " EnableSingleInputRendering="false" />
                                    <TimePopupButton Visible="false" />
                                </telerik:RadTimePicker>
                            </li>
                            <li class="rsTimePick">
                                <label for='<%= EndDate.ClientID %>_dateInput_text'>
                                    <%= Owner.Localization.AdvancedTo%></label><%--
    							
                                    --%><telerik:RadDatePicker runat="server" ID="EndDate" CssClass="rsAdvDatePicker"
                                        Width="83px" SharedCalendarID="SharedCalendar" Skin='<%# Owner.Skin %>' Culture='<%# Owner.Culture %>'>
                                        <DatePopupButton Visible="False"/>
                                        <DateInput ID="DateInput4" runat="server" DateFormat='<%# Owner.AdvancedForm.DateFormat %>'
                                            EmptyMessageStyle-CssClass="riError" EmptyMessage=" " EnableSingleInputRendering="false"/>
                                    </telerik:RadDatePicker>
                                <%--
    							
                                --%><telerik:RadTimePicker runat="server" ID="EndTime" CssClass="rsAdvTimePicker"
                                    Width="65px" Skin='<%# Owner.Skin %>' Culture='<%# Owner.Culture %>'>
                                    <TimeView ShowHeader="true" HeaderText="Sélectionner une heure de fin" runat="server" Skin='<%# Owner.Skin %>' ID="TimeViewEnd" />
                                    <DateInput ID="DateInput5" runat="server" EmptyMessageStyle-CssClass="riError" EmptyMessage=" " EnableSingleInputRendering="false"/>
                                    <TimePopupButton Visible="false" />
                                </telerik:RadTimePicker>
                            </li>
                        </ul>
                        <asp:RequiredFieldValidator runat="server" ID="StartDateValidator" ControlToValidate="StartDate"
                            EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />
                        <asp:RequiredFieldValidator runat="server" ID="StartTimeValidator" ControlToValidate="StartTime"
                            EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />
                        <asp:RequiredFieldValidator runat="server" ID="EndDateValidator" ControlToValidate="EndDate"
                            EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />
                        <asp:RequiredFieldValidator runat="server" ID="EndTimeValidator" ControlToValidate="EndTime"
                            EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />
                       <asp:CustomValidator runat="server" ID="DurationValidator" ControlToValidate="StartDate"
                            EnableClientScript="false" Display="Dynamic" CssClass="rsValidatorMsg rsInvalid"
                            OnServerValidate="DurationValidator_OnServerValidate" />
     
                    </asp:Panel>
                    <telerik:RadCalendar runat="server" ID="SharedCalendar" Skin='<%# Owner.Skin %>'
                        CultureInfo='<%# Owner.Culture %>'                    
                        EnableNavigation="true"
                        DayCellToolTipFormat="dddd, dd MMMM, yyyy" EnableMultiSelect="False" 
                        FirstDayOfWeek="Monday" ShowDayCellToolTips="False"
                        EnableMonthYearFastNavigation="False" />
                </asp:Panel>
            </div>
            <asp:Panel runat="server" ID="ButtonsPanel" CssClass="rsAdvancedSubmitArea">
                <div class="rsAdvButtonWrapper">
                    <asp:LinkButton runat="server" ID="UpdateButton" CssClass="rsAdvEditSave">
    					<span><%= Owner.Localization.Save %></span>
                    </asp:LinkButton>
                    <asp:LinkButton runat="server" ID="CancelButton" CssClass="rsAdvEditCancel" CommandName="Cancel"
                        CausesValidation="false">
    					<span><%= Owner.Localization.Cancel %></span>
                    </asp:LinkButton>
                </div>
            </asp:Panel>
        </div>
    </div>
    
    ------------------------------------------   
    AdvancedFormCS.ascx.cs
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using Telerik.Web.UI;
    using Telerik.Web.UI.Calendar;
     
    namespace SchedulerTemplatesCS
    {
    	/// <summary>
    	/// Specifies the advanced form mode.
    	/// </summary>
    	public enum AdvancedFormMode
    	{
    		Insert, Edit
    	}
     
    	public partial class AdvancedForm : UserControl
    	{
    		#region Private members
     
    		private bool FormInitialized
    		{
    			get
    			{
    				return (bool) (ViewState["FormInitialized"] ?? false);
    			}
     
    			set
    			{
    				ViewState["FormInitialized"] = value;
    			}
    		}
     
    		private AdvancedFormMode mode = AdvancedFormMode.Insert;
     
    		#endregion
     
    		#region Protected properties
     
    		protected RadScheduler Owner
    		{
    			get
    			{
    				return Appointment.Owner;
    			}
    		}
     
    		protected Appointment Appointment
    		{
    			get
    			{
    				SchedulerFormContainer container = (SchedulerFormContainer) BindingContainer;
    				return container.Appointment;
    			}
    		}
     
    		#endregion
     
    		#region Public properties
     
    		public AdvancedFormMode Mode
    		{
    			get
    			{
    				return mode;
    			}
    			set
    			{
    				mode = value;
    			}
    		}
     
    		[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    		public string Subject
    		{
    			get
    			{
    				return SubjectText.Text;
    			}
     
    			set
    			{
    				SubjectText.Text = value;
    			}
    		}
     
    		[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    		public DateTime Start
    		{
    			get
    			{
                    DateTime result = StartDate.SelectedDate.Value.Date;
     
     
                        TimeSpan time = StartTime.SelectedDate.Value.TimeOfDay;
                        result = result.Add(time);
     
                    return Owner.DisplayToUtc(result);
                }
     
    			set
    			{
    				StartDate.SelectedDate = Owner.UtcToDisplay(value);
    				StartTime.SelectedDate = Owner.UtcToDisplay(value);
    			}
    		}
     
    		[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    		public DateTime End
    		{
    			get
    			{
                    DateTime result = EndDate.SelectedDate.Value.Date;
     
                        TimeSpan time = EndTime.SelectedDate.Value.TimeOfDay;
                        result = result.Add(time);
     
                    return Owner.DisplayToUtc(result);
                }
     
    			set
    			{
    				EndDate.SelectedDate = Owner.UtcToDisplay(value);
    				EndTime.SelectedDate = Owner.UtcToDisplay(value);
    			}
    		}
     
    		#endregion
     
    		protected void Page_Load(object sender, EventArgs e)
    		{
    			UpdateButton.ValidationGroup = Owner.ValidationGroup;
    			UpdateButton.CommandName = Mode == AdvancedFormMode.Edit ? "Update" : "Insert";
     
    			InitializeStrings();
                SetDates();
            }
     
    		protected void DurationValidator_OnServerValidate(object source, ServerValidateEventArgs args)
    		{
    			args.IsValid = (End - Start) > TimeSpan.Zero;
    		}
     
    		#region Private methods
     
    		private void InitializeStrings()
    		{
    			StartDateValidator.ErrorMessage = Owner.Localization.AdvancedStartDateRequired;
                
    			StartDateValidator.ValidationGroup = Owner.ValidationGroup;
     
    			StartTimeValidator.ErrorMessage = Owner.Localization.AdvancedStartTimeRequired;
    			StartTimeValidator.ValidationGroup = Owner.ValidationGroup;
     
    			EndDateValidator.ErrorMessage = Owner.Localization.AdvancedEndDateRequired;
    			EndDateValidator.ValidationGroup = Owner.ValidationGroup;
     
    			EndTimeValidator.ErrorMessage = Owner.Localization.AdvancedEndTimeRequired;
    			EndTimeValidator.ValidationGroup = Owner.ValidationGroup;
     
    			DurationValidator.ErrorMessage = Owner.Localization.AdvancedStartTimeBeforeEndTime;
                               DurationValidator.ValidationGroup = Owner.ValidationGroup;
                               DurationValidator.Visible = true;
     
                               SharedCalendar.FastNavigationSettings.OkButtonCaption = Owner.Localization.AdvancedCalendarOK;
                               SharedCalendar.FastNavigationSettings.CancelButtonCaption = Owner.Localization.AdvancedCalendarCancel;
                               SharedCalendar.FastNavigationSettings.TodayButtonCaption = Owner.Localization.AdvancedCalendarToday;
     
    		}
     
            private void SetDates()
            {
                DayOfWeek dayToday = DateTime.Now.DayOfWeek;
                int nbJourASoustraire = 0;
                switch (dayToday)
                {
                    case DayOfWeek.Monday:
                        break;
                    case DayOfWeek.Tuesday:
                        nbJourASoustraire = 1;
                        break;
                    case DayOfWeek.Wednesday:
                        nbJourASoustraire = 2;
                        break;
                    case DayOfWeek.Thursday:
                        nbJourASoustraire = 3;
                        break;
                    case DayOfWeek.Friday:
                        nbJourASoustraire = 4;
                        break;
                    case DayOfWeek.Saturday:
                        nbJourASoustraire = 5;
                        break;
                    case DayOfWeek.Sunday:
                        nbJourASoustraire = 6;
                        break;
                }
     
                DateTime minDate = DateTime.Now.AddDays(-nbJourASoustraire);
                SharedCalendar.RangeMinDate = minDate;
                SharedCalendar.RangeMaxDate = minDate.AddDays(6);
            }
           
     
    		#endregion
    	}
    }



    ----------------------------------------




    Part of my Scheduler.aspx :
    <telerik:RadScheduler runat="server" ID="rsPlanning" OnClientAppointmentClick="appointmentClick" RowHeight="35px" ValidationGroup="Toto"
                        Culture="fr-FR" DataEndField="DT_FIN" DataKeyField="ID_PLANNING" DataSourceID="edsPlanning"
                        DataStartField="DT_DEBUT" DataSubjectField="SUJET" GroupBy="Groupement"
                        OnAppointmentInsert="rsPlanning_AppointmentInsert" OnAppointmentDelete="rsPlanning_AppointmentDelete"
                        SelectedView="TimelineView" ShowFooter="False" ShowViewTabs="False" WorkDayEndTime="05:00:00"
                        WorkDayStartTime="05:00:00" DayEndTime="05:00:00" DayStartTime="05:00:00" LastDayOfWeek="Monday"
                        FirstDayOfWeek="Monday" ShowHeader="True" BorderColor="#999999" BorderWidth="1"
                        BorderStyle="Solid" ShowAllDayRow="True"
                        ShowNavigationPane="False" Skin="Windows7" OnNavigationCommand="rsPlanning_NavigationCommand"
                        AppointmentStyleMode="Default" OnAppointmentDataBound="rsPlanning_AppointmentDataBound"
                        OnClientAppointmentMoving="onClientAppointmentMovingHandler" AllowInsert="False"
                        OnClientAppointmentResizeEnd="onClientAppointmentResizEndHandler"
                        EditFormDateFormat="dddd" OnClientFormCreated="schedulerFormCreated" OverflowBehavior="Expand">
                        <Localization AdvancedEditAppointment="Editer affectation" AdvancedNewAppointment="Nouvelle affectation"
                            AdvancedCalendarCancel="Annuler" AdvancedClose="Fermer" AdvancedEndDateRequired="Date de fin requise"
                            AdvancedEndTimeRequired="Heure de fin requise" AdvancedFrom="Date début" AdvancedNoEndDate="Pas date de fin"
                            AdvancedStartDateRequired="Date de début requise" AdvancedStartTimeBeforeEndTime="la date de début doit précéder la date de fin"
                            AdvancedStartTimeRequired="Heure de début requise" AdvancedSubject="Gare" Cancel="Annuler" 
                            ConfirmCancel="Annuler" ConfirmDeleteText="Etes-vous sûr de vouloir supprimer cette affectation ?"
                            ConfirmDeleteTitle="Suppression affectation" ContextMenuDelete="Supprimer" ContextMenuEdit="Editer"
                            Save="Enregistrer" AdvancedTo="Date fin" />
                        <TimelineView GroupingDirection="Vertical" NumberOfSlots="21" ColumnHeaderDateFormat="dddd"
                            EnableExactTimeRendering="True" SlotDuration="08:00:00" StartTime="05:00:00"
                            TimeLabelSpan="3" HeaderDateFormat="dddd" />
                        <ExportSettings FileName="PlanningExport" OpenInNewWindow="True">
                            <Pdf PageTitle="Planning d'affectation des gares" Title="Planning" PaperSize="A4" PageLeftMargin="0mm" PageRightMargin="0mm"/>
                        </ExportSettings>
                        <AdvancedForm EnableResourceEditing="False" MaximumHeight="200px" Modal="True" Width="500px" />
                        <ResourceTypes>
                            <telerik:ResourceType DataSourceID="edsGptPlanning" ForeignKeyField="ID_GROUPEMENT"
                                KeyField="ID_GROUPEMENT" Name="Groupement" TextField="NOM_GROUPEMENT" />
                            <telerik:ResourceType ForeignKeyField="ID_GARE" KeyField="ID_GARE" Name="Gare" DataSourceID="edsGare"
                                TextField="LI_GARE" />
                        </ResourceTypes>
                        <AppointmentContextMenuSettings EnableDefault="True" />
                        <AdvancedEditTemplate>
                            <scheduler:AdvancedForm runat="server" ID="AdvancedEditForm1" Mode="Edit" Subject='<%# Bind("Subject") %>'
                                Start='<%# Bind("Start") %>' End='<%# Bind("End") %>' />
                        </AdvancedEditTemplate>
                    </telerik:RadScheduler>




  2. CLAUDE LLOP
    CLAUDE LLOP avatar
    10 posts
    Member since:
    Mar 2008

    Posted 23 Apr 2012 Link to this post

    Anybody ???
  3. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 23 Apr 2012 Link to this post

    Hello Claude,

    The video provided below demonstrates how the duration validation of an appointment, when inserted trough the advanced insert form of RadScheduler, should function: http://screencast.com/t/GmlLSOqsuNJN.
    Could you explain what exactly you are trying to achieve? It would be great if you could provide us with a sample project, via a support ticket, showing the scenario you are implementing in action.

    Also, what version of RadControls do you use in your application?

    Kind regards,
    Ivana
    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