+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / RadScheduler Error: OnClientClose is not defined

RadScheduler Error: OnClientClose is not defined

11 posts, 2 answered
  1. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    29 Oct 2010
    Link to this post
    Hi,

    I am having trouble embedding a particular user control in the radscheduler advanced edit/insert forms. For a little background, I am overriding the EventItemsEdit template of the Events Module with some custom functionality. I created the following user control to upload two custom attachments. The following is the user control markup.

    <%@ Control Language="C#" %>
     
    <telerik:RadScriptBlock ID="scriptBlock" runat="server">
        <script type="text/javascript">
                //<![CDATA[
            var $ = $telerik.$;
            var currentLink = null;
            var briefLinkId = null;
            var presentationLinkId = null;
     
            var briefSfrefHiddenId = null;
            var briefHrefHiddenId = null;
            var briefLinkTitleHiddenId = null;
     
            var presentationSfrefHiddenId = null;
            var presentationHrefHiddenId = null;
            var presentationLinkTitleHiddenId = null;
            function openWin() {
                var oWnd = radopen("http://localhost/medpacofficial/Sitefinity/UserControls/Dialogs/DocumentEditorDialog.aspx", "RadWindow1");
                return false;
            }
     
           
            function OnClientClose(oWnd, args) {
                //get the transferred arguments
     
                if (currentLink != null) {
                    var arg = args.get_argument();
                    if (arg) {
                        arg.id = "temp";
                        var val = $("#temp");
                        if (val != null)
                            val.remove();
     
                        $("#hiddenCurrentElement").append(arg);
                        val = $("#temp");
     
                        if (currentLink == 'brief') {
                            $("input[id$='hiddenBriefSfref']").val(val.attr("sfref"));
                            $("input[id$='hiddenBriefHref']").val(val.attr("href"));
                            $("input[id$='hiddenBriefLinkText']").val(val.text());
     
                            var briefLink = $("a[id$='briefLink']");
                            briefLink.attr("href", val.attr("href"));
                            briefLink.text(val.text());
     
                            $("#" + briefLink.attr("id") + "ItemSelector").text("Change");
                        }
                        else if (currentLink == 'presentation') {
                            $("input[id$='hiddenPresentationSfref']").val(val.attr("sfref"));
                            $("input[id$='hiddenPresentationHref']").val(val.attr("href"));
                            $("input[id$='hiddenPresentationLinkText']").val(val.text());
     
                            var presentationLink = $("a[id$='presentationLink']");
                            presentationLink.attr("href", val.attr("href"));
                            presentationLink.text(val.text());
     
                            $("#" + presentationLink.attr("id") + "ItemSelector").text("Change");
                        }
                    }
                }
            }
            //]]>
        </script>
    </telerik:RadScriptBlock>
     
     
     
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" Modal="true"
        ReloadOnShow="true" runat="server" Skin="Vista" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" Width="700" Height="800"
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
     
    <ul>
        <li>
            <asp:Label ID="briefLabel" runat="server" Text="Brief" />
            <asp:HyperLink ID="briefLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="briefLinkItemSelector" runat="server" OnClientClick="currentLink='brief';openWin();return false;"
                Text="Change" />
            <asp:HiddenField ID="hiddenBriefSfref" runat="server" />
            <asp:HiddenField ID="hiddenBriefHref" runat="server" />
            <asp:HiddenField ID="hiddenBriefLinkText" runat="server" />
        </li>
        <li>
            <asp:Label ID="presentationLabel" runat="server" Text="Presentation" />
            <asp:HyperLink ID="presentationLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="presentationLinkItemSelector" runat="server" OnClientClick="currentLink='presentation';openWin();return false;"
                Text="Change" />
           
            <asp:HiddenField ID="hiddenPresentationSfref" runat="server" />
            <asp:HiddenField ID="hiddenPresentationHref" runat="server" />
            <asp:HiddenField ID="hiddenPresentationLinkText" runat="server" />
        </li>
    </ul>
     
    <div id="hiddenCurrentElement" style="display:none"/>


    When I embed this control inside the advanced form of a RadScheduler, the following error is being thrown:
    OnClientClose is not defined. and Error: Sys.InvalidOperationException: Component 'ctl00_ContentPlaceHolder1_contolPanel_ctl00_ctl01_ctl00_ctl00_ctl00_agendaItems_ctl00_ctl00_RadScheduler1_Form_attachments_ctl00_ctl00_RadWindow1' was not found.


    When I embed this control directly inside the EventsItemEdit template, it works as expected, a radwindow opening when I click either the Brief link or the Presentation link. The following is the user control that contains the RadScheduler.

    <%@ Control Language="C#" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register TagPrefix="medpac" Namespace="Medpac.Meetings.WebControls.Admin" Assembly="Medpac.Meetings" %>
     
    <div class="agendaItems">
        <asp:Panel ID="schedulerPanel" runat="server">
            <telerik:RadScheduler runat="server" ID="RadScheduler1" ShowViewTabs="false" OverflowBehavior="Scroll"
                DayStartTime="00:00:00" DayEndTime="18:00:00" AdvancedForm-Enabled="true" StartEditingInAdvancedForm="true" StartInsertingInAdvancedForm="true"
                Skin="Vista" CustomAttributeNames="Contact,BriefContentID,PresentationContentID,EventID" MinutesPerRow="15">
                <AdvancedForm Modal="true" />
                <WeekView HeaderDateFormat="d" />
                <AppointmentTemplate>
                    <div>
                        <%# Eval("Subject") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Description") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Start") %> - <%# Eval("End") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Contact") %>
                    </div>
                </AppointmentTemplate>
                <AdvancedEditTemplate>
                    <medpac:AgendaItemAttachments ID="attachments" runat="server" />
                </AdvancedEditTemplate>
                <AdvancedInsertTemplate>
                    <medpac:AgendaItemAttachments ID="attachments" runat="server" />
                </AdvancedInsertTemplate>
                <TimelineView UserSelectable="false" />
     
                <TimeSlotContextMenuSettings EnableDefault="true" />
                <AppointmentContextMenuSettings EnableDefault="true" />
            </telerik:RadScheduler>
        </asp:Panel>
    </div>


    This example is just a simplified version of what I am actually doing. The complete version will have the AgendaItemsAttachments user control embedded in a AgendaItemAdvancedForm user control. But the same error is being thrown when the AgendaItemsAttachments control is embedded in that user control also. The AgendaItemsAttachments  form works when it's inside the EventsItemEdit template or a standalone webpage. Do you have any idea what could be wrong?

    Thanks for your help in advance,
    Bobby
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Nov 2010
    Link to this post
    Hello Bobby,

    Thank you for using our services.

    Can you please explain how you are binding the control, and if this control is a custom control or a user control? We are having some hard time recreating the control from the supplied markup. It would be nice if you can wrap up a sample project where we can observe the behavior and see what might be wrong.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    04 Nov 2010
    Link to this post
    I have a sample project created but I am not sure how to upload a .zip file. The attachment upload says it only accepts .gif,.jpg, .jpeg, and .png files. Not sure. I will just post all my sample code here. In the port of my code to this sample, my scheduler_FormCreated event handler is not being called. I can't figure out why, everything looks correct to me. Can you help with these issues? I am stuck. Thanks in advance.

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
      
    <%@ Register Namespace="Test" TagPrefix="sample" Assembly="App_Code" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
        <style type="text/css">
            .RadScheduler .rsAptSubject 
            {
                 text-align: left; 
                 padding: 4px 0 1px;
                 margin: 0 0 3px;
                 font-size: 12px; 
                 font-weight: bold; 
                 color: #369;
                 height: 17px;
                 border-bottom: 1px solid #99DEFD;
                 width: 100%; 
             }     
           
             .RadScheduler .rsAdvancedEdit .RadColorPicker label
             {
                text-align: left;
                display: block;
                padding: 0;
             
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="rdScript" runat="server"/>
              
            <sample:AgendaItems ID="agendaItems" runat="server" />
        </form>
    </body>
    </html>

    AgendaItems.ascx
    <%@ Control Language="C#" %>
      
      
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register TagPrefix="sample" Namespace="Medpac.Meetings.WebControls.Admin" Assembly="Medpac.Meetings" %>
      
    <div class="agendaItems">
        <asp:Panel ID="schedulerPanel" runat="server">
         
            <telerik:RadScheduler runat="server" ID="RadScheduler1" ShowViewTabs="false" OverflowBehavior="Scroll"
                DayStartTime="00:00:00" DayEndTime="18:00:00" AdvancedForm-Enabled="true"
                Skin="Vista" CustomAttributeNames="Contact,BriefContentID,PresentationContentID,EventID" MinutesPerRow="15">
                <AdvancedForm Modal="true" />
                <WeekView HeaderDateFormat="d" />
                <AppointmentTemplate>
                    <div>
                        <%# Eval("Subject") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Description") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Start") %> - <%# Eval("End") %>
                    </div>
                    <div style="font-style: italic;">
                        <%# Eval("Contact") %>
                    </div>
                </AppointmentTemplate>
                <AdvancedEditTemplate>
                    <sample:AgendaItemAdvancedForm runat="server" ID="AdvancedEditForm1" 
                        Mode="Edit" 
                        Subject='<%# Bind("Subject") %>'
                        Start='<%# Bind("Start") %>'
                        End='<%# Bind("End") %>'
                        Contact='<% Bind("Contact") %>'
                        PresentationContentID='<%# Bind("PresentationContentID") %>'
                        BriefContentID='<%# Bind("BriefContentID") %>' />
                </AdvancedEditTemplate>
                <AdvancedInsertTemplate>
                     <sample:AgendaItemAdvancedForm runat="server" ID="AdvancedInsertForm1" 
                         Mode="Insert"
                         Subject='<%# Bind("Subject") %>'
                         Start='<%# Bind("Start") %>'
                         End='<%# Bind("End") %>'
                         Contact='<%# Bind("Contact") %>'
                         PresentationContentID='<%# Bind("PresentationContentID") %>'
                         BriefContentID='<%# Bind("BriefContentID") %>' />
                </AdvancedInsertTemplate>
      
                <TimelineView UserSelectable="false" />
                <TimeSlotContextMenuSettings EnableDefault="true" />
                <AppointmentContextMenuSettings EnableDefault="true" />
            </telerik:RadScheduler>
        </asp:Panel>
    </div>


    AgendaItemAdvancedForm.ascx
    <%@ Control Language="C#" %>
      
    <%@ Register TagPrefix="sample" Assembly="App_Code" Namespace="Test" %>
      
    <div class="rsAdvancedEdit" style="position: relative">
        <%-- Title bar. --%>
        <div class="rsAdvTitle">
            <%-- The rsAdvInnerTitle element is used as a drag handle when the form is modal. --%>
            <h1 class="rsAdvInnerTitle">
                <asp:Literal ID="Literal1" runat="server" Text='Edit Appointment' />
            </h1>
            <asp:LinkButton runat="server" ID="AdvancedEditCloseButton" CssClass="rsAdvEditClose"
                    CommandName="Cancel" CausesValidation="false" ToolTip='Clost'>
                <asp:Literal ID="lit" runat="server" Text='Clost' />
            </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">
                        <telerik:RadTextBox runat="server" ID="SubjectText" Width="100%" Label='Title'
                            Text='<%# Eval("Subject") %>' />
                        <asp:RequiredFieldValidator runat="server" ID="SubjectValidator" ControlToValidate="SubjectText"
                                EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />
      
                        <ul class="rsTimePickers">
                            <asp:Label ID="labelMeetingDate" runat="server" Text='Meeting Date:' AssociatedControlID="meetingDate" />
                            <telerik:RadDateInput ID="meetingDate" runat="server" SelectedDate='<%# Eval("Start") %>' ReadOnly="true" />
                            <li class="rsTimePick">
                                <asp:Label ID="labelStartTime" runat="server" Text='"Start' AssociatedControlID="StartTime" />
                                <telerik:RadTimePicker runat="server" ID="StartTime" CssClass="rsAdvTimePicker" ShowPopupOnFocus="true" TimePopupButton-Visible="false" SelectedDate='<%# Eval("Start") %>'>
                                      
                                    <TimeView ID="TimeView1" runat="server" Columns="3" RenderDirection="Horizontal" ShowHeader="true" StartTime="08:00"
                                        EndTime="18:00" Interval="00:30" />
                                </telerik:RadTimePicker>
                            </li>
                            <li class="rsTimePick">
                                <asp:Label ID="labelEndTime" runat="server" Text='End' AssociatedControlID="EndTime" />
                                <telerik:RadTimePicker runat="server" TimePopupButton-Visible="false" ShowPopupOnFocus="true" ID="EndTime" CssClass="rsAdvTimePicker" Width="65px"  SelectedDate='<%# Eval("End") %>'>
                                      
                                    <TimeView ID="TimeView2" runat="server" Columns="3" RenderDirection="Horizontal" ShowHeader="true" StartTime="08:00" 
                                        EndTime="18:00" Interval="00:30" />
                                </telerik:RadTimePicker>
                            </li>
                        </ul>
                        <asp:RequiredFieldValidator runat="server" ID="StartTimeValidator" ControlToValidate="StartTime"
                            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="StartTime"
                            EnableClientScript="false" Display="Dynamic" CssClass="rsValidatorMsg rsInvalid"
                            />
                    </asp:Panel>
                    <asp:Panel runat="server" ID="AdvancedControlsPanel" CssClass="rsAdvMoreControls">
                            <div class="qsfexAdvEditControlWrapper clear">
                                <telerik:RadTextBox ID="ContactText" runat="server" Text='<%# Bind("Contact") %>' Width="98%" Label='Contact' ></telerik:RadTextBox>
                            </div>
                            <br />
                            <div class="qsfexAdvEditControlWrapper clear">
                                <h3>
                                    <asp:Label ID="Label5" runat="server">
                                        <asp:Literal ID="Literal7" runat="server" Text="Agenda Attachments" />
                                        * <em id="TitleLabel" runat="server"></em>
                                    </asp:Label>
                                </h3>
                                <fieldset class="">
                                    <div class="clear"
                                        <sample:AgendaItemAttachments ID="attachments" runat="server" BriefContentID='<%# Bind("BriefContentID") %>' PresentationContentID='<%# Bind("PresentationContentID") %>' />
                                    </div>
                                </fieldset>
                            </div>
                    </asp:Panel>
                   
                </asp:Panel>
            </div>
            <asp:Panel runat="server" ID="ButtonsPanel" CssClass="rsAdvancedSubmitArea">
                <div class="rsAdvButtonWrapper">
                    <asp:LinkButton runat="server" ID="UpdateButton" CssClass="rsAdvEditSave">
                        <span><asp:Literal ID="Literal3" runat="server" Text='Save' /></span>
                    </asp:LinkButton>
    <asp:LinkButton runat="server" ID="CancelButton" CssClass="rsAdvEditCancel" CommandName="Cancel"
    CausesValidation="false">
                        <span>Cancel</span>
                    </asp:LinkButton>
                </div>
            </asp:Panel>
        </div>
    </div>

    AgendaItemsAttachment.ascx (In this file, I hardcoded the path to the DocumentEditorDialog.aspx page located at ~/Sitefinity/UserControls/Dialogs/DocumentEditorDialog.aspx. This will need to be changed in your code.
    <%@ Control Language="C#" %>
      
    <telerik:RadScriptBlock ID="scriptBlock" runat="server">
        <script type="text/javascript">
                //<![CDATA[
            var $ = $telerik.$;
            var currentLink = null;
            var briefLinkId = null;
            var presentationLinkId = null;
      
            var briefSfrefHiddenId = null;
            var briefHrefHiddenId = null;
            var briefLinkTitleHiddenId = null;
      
            var presentationSfrefHiddenId = null;
            var presentationHrefHiddenId = null;
            var presentationLinkTitleHiddenId = null;
            function openWin() {
                var oWnd = radopen("http://localhost/medpacofficial/Sitefinity/UserControls/Dialogs/DocumentEditorDialog.aspx", "RadWindow1");
                return false;
            }
      
      
            function OnClientClose(oWnd, args) {
                //get the transferred arguments
      
                if (currentLink != null) {
                    var arg = args.get_argument();
                    if (arg) {
                        arg.id = "temp";
                        var val = $("#temp");
                        if (val != null)
                            val.remove();
      
                        $("#hiddenCurrentElement").append(arg);
                        val = $("#temp");
      
                        if (currentLink == 'brief') {
                            $("input[id$='hiddenBriefSfref']").val(val.attr("sfref"));
                            $("input[id$='hiddenBriefHref']").val(val.attr("href"));
                            $("input[id$='hiddenBriefLinkText']").val(val.text());
      
                            var briefLink = $("a[id$='briefLink']");
                            briefLink.attr("href", val.attr("href"));
                            briefLink.text(val.text());
      
                            $("#" + briefLink.attr("id") + "ItemSelector").text("Change");
                        }
                        else if (currentLink == 'presentation') {
                            $("input[id$='hiddenPresentationSfref']").val(val.attr("sfref"));
                            $("input[id$='hiddenPresentationHref']").val(val.attr("href"));
                            $("input[id$='hiddenPresentationLinkText']").val(val.text());
      
                            var presentationLink = $("a[id$='presentationLink']");
                            presentationLink.attr("href", val.attr("href"));
                            presentationLink.text(val.text());
      
                            $("#" + presentationLink.attr("id") + "ItemSelector").text("Change");
                        }
                    }
                }
            }
            //]]>
        </script>
    </telerik:RadScriptBlock>
      
      
      
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" Modal="true" 
        ReloadOnShow="true" runat="server" Skin="Vista" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" Width="700" Height="800"
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
      
    <ul>
        <li>
            <asp:Label ID="briefLabel" runat="server" Text="Brief" />
            <asp:HyperLink ID="briefLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="briefLinkItemSelector" runat="server" OnClientClick="currentLink='brief';openWin();return false;"
                Text="Change" />
            <asp:HiddenField ID="hiddenBriefSfref" runat="server" />
            <asp:HiddenField ID="hiddenBriefHref" runat="server" />
            <asp:HiddenField ID="hiddenBriefLinkText" runat="server" />
        </li>
        <li>
            <asp:Label ID="presentationLabel" runat="server" Text="Presentation" />
            <asp:HyperLink ID="presentationLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="presentationLinkItemSelector" runat="server" OnClientClick="currentLink='presentation';openWin();return false;"
                Text="Change" />
            
            <asp:HiddenField ID="hiddenPresentationSfref" runat="server" />
            <asp:HiddenField ID="hiddenPresentationHref" runat="server" />
            <asp:HiddenField ID="hiddenPresentationLinkText" runat="server" />
        </li>
    </ul>
      
    <div id="hiddenCurrentElement" style="display:none"/>


    AgendaItems.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Cms.Web.UI;
      
    namespace Test
    {
      
        /// <summary>
        /// AgendaItems are Events that exists within Meetings(a.k.a Events). 
        /// For example, We have a Meeting scheduled for November 4, 2010. In that meeting we have the following agenda items.
        /// Agenda Item 1 will begin at 11:00 am and last until 12:00pm.
        /// Agenda Item 2 will begin at 12:00 pm and last until 12:30pm.
        /// An agenda item can have two attachments(documents) associated with it. A brief and a presentation.
        /// This is a simplified example, so this control will only show one agenda item. The brief and presentation attachments 
        /// link to google and yahoo. In the real application they would link to documents from the document library.
        /// </summary>
        public class AgendaItems : SimpleControl
        {
            public string ProviderName
            {
                get
                {
                    string providerName = string.Empty;
                    if (!string.IsNullOrEmpty(ViewState["ProviderName"] as string))
                        providerName = ViewState["ProviderName"] as string;
                    return providerName;
                }
                set
                {
                    ViewState["ProviderName"] = value;
                }
            }
      
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
            }
      
            protected override void InitializeControls(System.Web.UI.Control controlContainer)
            {
                base.InitializeControls(controlContainer);
      
                RadScheduler scheduler = Scheduler;
      
                scheduler.DataKeyField = "ID";
                scheduler.DataSubjectField = "Title";
                scheduler.DataStartField = "Start";
                scheduler.DataEndField = "End";
      
                scheduler.AllowDelete = true;
                scheduler.AllowInsert = true;
                scheduler.AllowEdit = true;
      
                scheduler.SelectedView = SchedulerViewType.MultiDayView;
                scheduler.ShowNavigationPane = false;
                scheduler.MultiDayView.ShowResourceHeaders = false;
                scheduler.FormCreated += new SchedulerFormCreatedEventHandler(scheduler_FormCreated);
                  
                scheduler.SelectedDate = DateTime.Now;
                scheduler.DataSource = GetAgendaItems();
                scheduler.MultiDayView.NumberOfDays = 2;
                scheduler.DataBind();
            }
      
            protected void scheduler_AppointmentCommand(object sender, AppointmentCommandEventArgs e)
            {
                  
            }
      
            private IList<AgendaItem> GetAgendaItems()
            {
                DateTime now = DateTime.Now;
                DateTime elevenAm = now.Date;
                elevenAm += new TimeSpan(11, 00, 00);
      
                DateTime noon = now.Date;
                noon += new TimeSpan(12, 00, 00);
      
                DateTime twelve30 = now.Date;
                twelve30 += new TimeSpan(12, 30, 00);
      
                IList<AgendaItem> items = new List<AgendaItem> { new AgendaItem { Contact = "Bobby Williams", Start = elevenAm, End = noon, ID = Guid.NewGuid(), EventID = Guid.NewGuid(), Title = "This is a bogus 11 am agenda item lasting until noon", BriefContentID = Guid.NewGuid(), PresentationContentID = Guid.NewGuid() },
                                                                new AgendaItem { Contact = "Bobby Williams", Start = noon, End = twelve30, ID = Guid.NewGuid(), EventID = Guid.NewGuid(), Title = "This is a bogus noon agenda item lasting until 12:30pm", BriefContentID = Guid.NewGuid(), PresentationContentID = Guid.NewGuid() }
                                                            };
      
                return items;
            }
      
            protected void scheduler_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
            {
                RadScheduler scheduler = (RadScheduler)sender;
      
                AgendaItemAdvancedForm.ProviderName = ProviderName;
      
                if (e.Container.Mode == SchedulerFormMode.AdvancedInsert)
                {
                    AgendaItemAdvancedForm.AgendaID = null;
      
                    //     object b = DataBinder.Eval(e.Container.Appointment, "BriefContentID");
                    //     object p = DataBinder.Eval(e.Container.Appointment, "PresentationContentID");
                }
                else
                {
                    if (e.Container.Mode == SchedulerFormMode.AdvancedEdit)
                    {
                        AgendaItemAdvancedForm.AgendaID = (Guid)e.Container.Appointment.ID;
                    }
                }
            }
      
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/AgendaItems.ascx";
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            private RadScheduler Scheduler
            {
                get
                {
                    return base.Container.GetControl<RadScheduler>("RadScheduler1", true);
                }
            }
      
            private AgendaItemAdvancedForm AgendaItemAdvancedForm
            {
                get
                {
                    return base.Container.GetControl<AgendaItemAdvancedForm>("AdvancedEditForm1", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
        }
    }


    AgendaItemAdvancedForm.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.ComponentModel;
    using System.Data.SqlTypes;
    using Telerik.Cms.Web.UI;
      
    namespace Test
    {
        public class AgendaItemAdvancedForm : SimpleControl
        {
            /// <summary>
            /// Specifies the advanced form mode.
            /// </summary>
            public enum AdvancedFormMode
            {
                Insert, Edit
            }
      
            private AdvancedFormMode mode = AdvancedFormMode.Insert;
      
            public AdvancedFormMode Mode
            {
                get
                {
                    return mode;
                }
                set
                {
                    mode = value;
                }
            }
      
            private DateTime? MeetingDate
            {
                get
                {
                    return (ViewState["MeetingDate"] == null) ? null : (DateTime?)ViewState["MeetingDate"];
                }
                set
                {
                    ViewState["MeetingDate"] = value;
                }
            }
      
            public string ProviderName
            {
                get
                {
                    string providerName = string.Empty;
                    if (!string.IsNullOrEmpty(ViewState["ProviderName"] as string))
                        providerName = ViewState["ProviderName"] as string;
                    return providerName;
                }
                set
                {
                    ViewState["ProviderName"] = value;
                }
            }
      
            protected override void InitializeControls(System.Web.UI.Control controlContainer)
            {
                base.InitializeControls(controlContainer);
                StartTime.Skin = Owner.Skin;
                StartTime.Culture = Owner.Culture;
                EndTime.Skin = Owner.Skin;
                EndTime.Culture = Owner.Culture;
      
                UpdateButton.ValidationGroup = Owner.ValidationGroup;
                UpdateButton.CommandName = Mode == AdvancedFormMode.Edit ? "Update" : "Insert";
      
                DurationValidator.ServerValidate += new ServerValidateEventHandler(DurationValidator_OnServerValidate);
            }
      
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/AgendaItemAdvancedForm.ascx";
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            protected RadScheduler Owner
            {
                get
                {
                    return Appointment.Owner;
                }
            }
      
            protected Appointment Appointment
            {
                get
                {
                    SchedulerFormContainer container = (SchedulerFormContainer)BindingContainer;
                    return container.Appointment;
                }
            }
      
            protected void DurationValidator_OnServerValidate(object source, ServerValidateEventArgs args)
            {
                args.IsValid = (End - Start) > TimeSpan.Zero;
            }
      
            private bool FormInitialized
            {
                get
                {
                    return (bool)(ViewState["FormInitialized"] ?? false);
                }
      
                set
                {
                    ViewState["FormInitialized"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public string Subject
            {
                get
                {
                    return SubjectText.Text;
                }
      
                set
                {
                    SubjectText.Text = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid? AgendaID
            {
                get
                {
                    return (Guid?)ViewState["AgendaID"];
                }
                set
                {
                    ViewState["AgendaID"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid MeetingID
            {
                get
                {
                    return (Guid)ViewState["MeetingID"];
                }
                set
                {
                    ViewState["MeetingID"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public DateTime Start
            {
                get
                {
                    DateTime returnValue = SqlDateTime.MaxValue.Value;
                    DateTime? result = MeetingDate;
                    if (result.HasValue)
                    {
                        TimeSpan time = StartTime.SelectedDate.Value.TimeOfDay;
                        returnValue = result.Value.Add(time);
                    }
      
                    return returnValue;
                }
                set
                {
                    MeetingDate = value.Date;
                    StartTime.SelectedDate = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid? PresentationContentID
            {
                get
                {
                    return (Guid?)ViewState["PresentationContentID"];
                }
                set
                {
                    ViewState["PresentationContentID"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid? BriefContentID
            {
                get
                {
                    return (Guid?)ViewState["BriefContentID"];
                }
                set
                {
                    ViewState["BriefContentID"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public DateTime End
            {
                get
                {
                    DateTime returnValue = SqlDateTime.MaxValue.Value;
                    DateTime? result = MeetingDate;
                    if (result.HasValue)
                    {
                        TimeSpan time = EndTime.SelectedDate.Value.TimeOfDay;
                        returnValue = result.Value.Add(time);
                    }
                    return returnValue;
                }
                set
                {
                    EndTime.SelectedDate = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public string Contact
            {
                get
                {
                    return ContactText.Text;
                }
                set
                {
                    ContactText.Text = value;
                }
            }
      
            public RadTimePicker StartTime
            {
                get
                {
                    return base.Container.GetControl<RadTimePicker>("StartTime", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
      
            public RadTimePicker EndTime
            {
                get
                {
                    return base.Container.GetControl<RadTimePicker>("EndTime", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
      
            public RadTextBox SubjectText
            {
                get
                {
                    return base.Container.GetControl<RadTextBox>("SubjectText", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
      
            public RadTextBox ContactText
            {
                get
                {
                    return base.Container.GetControl<RadTextBox>("ContactText", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
      
            public CustomValidator DurationValidator
            {
                get
                {
                    return base.Container.GetControl<CustomValidator>("DurationValidator", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
      
            public LinkButton UpdateButton
            {
                get
                {
                    return base.Container.GetControl<LinkButton>("UpdateButton", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
                }
            }
        }
    }


    AgendaItemAttachments.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using System.ComponentModel;
    using Telerik.Cms.Engine;
    using Telerik.Framework.Web;
    using Telerik.Libraries;
      
    namespace Test
    {
        public class AgendaItemAttachments : SimpleControl
        {
            private const string sfRef = "sfRef";
            private LibraryManager libraryManger;
      
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/AgendaItemAttachments.ascx";
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            private LibraryManager LibManager
            {
                get
                {
                    if (libraryManger == null)
                        libraryManger = new LibraryManager();
      
                    return libraryManger;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid? PresentationContentID
            {
                get
                {
                    return (Guid?)ViewState["PresentationContentID"];
                }
                set
                {
                    ViewState["PresentationContentID"] = value;
                }
            }
      
            [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
            public Guid? BriefContentID
            {
                get
                {
                    return (Guid?)ViewState["BriefContentID"];
                }
                set
                {
                    ViewState["BriefContentID"] = value;
                }
            }
      
            protected override void InitializeControls(System.Web.UI.Control controlContainer)
            {
                base.InitializeControls(controlContainer);
      
                if (BriefContentID.HasValue)
                {
                    BriefLink.Attributes[sfRef] = BriefContentID.Value.ToString();
                    BriefSfrefHidden.Value = BriefContentID.Value.ToString();
                    BriefLink.NavigateUrl = "http://www.google.com";
                    BriefLink.Text = "Google";
                }
                else
                {
                    BriefItemSelectorLink.Text = "Change";
                }
      
                if (PresentationContentID.HasValue)
                {
                    PresentationLink.Attributes[sfRef] = PresentationContentID.Value.ToString();
                    PresentationSfrefHidden.Value = PresentationContentID.Value.ToString();
                    PresentationLink.NavigateUrl = "http://www.yahoo.com";
                    PresentationLink.Text = "Yahoo";
                }
                else
                {
                    PresentationItemSelectorLink.Text = "Change";
                }
            }
      
            private HyperLink BriefLink
            {
                get
                {
                    return base.Container.GetControl<HyperLink>("briefLink", true);
                }
            }
      
            private HyperLink PresentationLink
            {
                get
                {
                    return base.Container.GetControl<HyperLink>("presentationLink", true);
                }
            }
      
            private LinkButton BriefItemSelectorLink
            {
                get
                {
                    return base.Container.GetControl<LinkButton>("briefLinkItemSelector", true);
                }
            }
      
            private LinkButton PresentationItemSelectorLink
            {
                get
                {
                    return base.Container.GetControl<LinkButton>("presentationLinkItemSelector", true);
                }
            }
      
            private HiddenField BriefSfrefHidden
            {
                get
                {
                    return base.Container.GetControl<HiddenField>("hiddenBriefSfref", true, TraverseMethod.BreadthFirst);
                }
            }
      
            private HiddenField PresentationSfrefHidden
            {
                get
                {
                    return base.Container.GetControl<HiddenField>("hiddenPresentationSfref", true, TraverseMethod.BreadthFirst);
                }
            }
        }
    }


    AgendaItem.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
      
      
    namespace Test
    {
        public class AgendaItem
        {
            private Guid agendaItemGuid;
            private Guid? briefContentId;
            private Guid? presentationContentId;
            private Guid eventID;
      
            private string title = string.Empty;
            private DateTime startTime;
            private DateTime endTime;
            private string contact = string.Empty;
      
            public Guid ID
            {
                get
                {
                    return agendaItemGuid;
                }
                set
                {
                    agendaItemGuid = value;
                }
            }
      
            /// <summary>
            /// The id of the meeting(a.k.a event) this agenda is a part of.
            /// </summary>
            public Guid EventID
            {
                get
                {
                    return eventID;
                }
                set
                {
                    eventID = value;
                }
            }
      
            public string Title
            {
                get
                {
                    return title;
                }
                set
                {
                    title = value;
                }
            }
      
            public Guid? BriefContentID
            {
                get
                {
                    return briefContentId;
                }
                set
                {
                    briefContentId = value;
                }
            }
      
            public Guid? PresentationContentID
            {
                get
                {
                    return presentationContentId;
                }
                set
                {
                    presentationContentId = value;
                }
            }
      
            public DateTime Start
            {
                get
                {
                    return startTime;
                }
                set
                {
                    startTime = value;
                }
            }
      
            public DateTime End
            {
                get
                {
                    return endTime;
                }
                set
                {
                    endTime = value;
                }
            }
      
            public string Contact
            {
                get
                {
                    return contact;
                }
                set
                {
                    contact = value;
                }
            }
        }
    }

  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    04 Nov 2010
    Link to this post
    Hi Bobby,

    Thank you for providing the code. I have set up the control and ran it inside a Sitefinity page. You can review the results in the attached screen cast. The scheduler_FormCreated event handler fires as expected. As well as the OnClientClose method.

    The only oddity I have noticed is how you reference the advanced edit form controls:
    private AgendaItemAdvancedForm AgendaItemAdvancedForm
    {
        get
        {
            return base.Container.GetControl<AgendaItemAdvancedForm>("AdvancedEditForm1", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
        }
    }

    This will return null as the AdvancedEditTemplate and AdvancedInsertTemplate are not instantiated when the control loads. You have to take another approach for referencing those controls. On the place where you need to use this control you have to check which template of the scheduler is not null and find the control in the template's control collection.

    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    04 Nov 2010
    Link to this post
    Hi,

    You are correct the control works as expected if I do an insert. I did not test that condition. The condition I was having trouble with was an advanced edit. The scheduler_FormCreated event handler does not fire. There is a post back to the server when I do an edit but the event is never called. Thanks for catching the possible null exception. Do you have any ideas why the advanced edit would not work but the advanced insert does?

    Thanks,
    Bobby
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Nov 2010
    Link to this post
    Hi Bobby,

    Thank you fro the clarification.

    It seems that the InitializeControls event is too early in the page/control life cycle to set the scheduler. This looses the control data and the control is rebound every time there is a postback. I have tried modifying the code a little by and managed to get the FormCreated event fired when you edit a control. Bellow is what I used instead of InitializeControls:
    protected override void InitializeControls(System.Web.UI.Control controlContainer)
    {
        base.InitializeControls(controlContainer);
    }
     
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        RadScheduler scheduler = Scheduler;
        scheduler.FormCreated += new SchedulerFormCreatedEventHandler(scheduler_FormCreated);
        if (!Page.IsPostBack)
        {
            scheduler.DataKeyField = "ID";
            scheduler.DataSubjectField = "Title";
            scheduler.DataStartField = "Start";
            scheduler.DataEndField = "End";
     
            scheduler.AllowDelete = true;
            scheduler.AllowInsert = true;
            scheduler.AllowEdit = true;
     
            scheduler.SelectedView = SchedulerViewType.MultiDayView;
            scheduler.ShowNavigationPane = false;
            scheduler.MultiDayView.ShowResourceHeaders = false;
     
     
            scheduler.SelectedDate = DateTime.Now;
     
            scheduler.MultiDayView.NumberOfDays = 2;
        }
        scheduler.DataSource = GetAgendaItems();
    }


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  7. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    06 Nov 2010
    Link to this post
    Hi,

        Thanks for all your help. This control works well outside of the EventsItemEdit control. When I use this custom control in a test page, everything works as expected. When I override the EventItemsEdit template of the Events Module and place the custom AgendaItems control on the page, the following error is thrown when the scheduler form is shown in either mode of AdvancedEdit or AdvancedInsert:

    OnClientClose is not defined.  AND

    Error: Sys.InvalidOperationException: Component 'ctl00_ContentPlaceHolder1_contolPanel_ctl00_ctl01_ctl00_ctl00_ctl00_agendaItems_ctl00_ctl00_RadScheduler1_Form_attachments_ctl00_ctl00_RadWindow1' was not found.

    Do you have any ideas why these errors are being thrown?

    Thanks again for all your help
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Nov 2010
    Link to this post
    Hello Bobby,

    Thank you for getting back to me.

    Initializing the shceduler control in CreateChildControls method I cannot reproduce the above error:
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        RadScheduler scheduler = Scheduler;
        scheduler.FormCreated += new SchedulerFormCreatedEventHandler(scheduler_FormCreated);
            scheduler.DataKeyField = "ID";
            scheduler.DataSubjectField = "Title";
            scheduler.DataStartField = "Start";
            scheduler.DataEndField = "End";
     
            scheduler.AllowDelete = true;
            scheduler.AllowInsert = true;
            scheduler.AllowEdit = true;
     
            scheduler.SelectedView = SchedulerViewType.MultiDayView;
            scheduler.ShowNavigationPane = false;
            scheduler.MultiDayView.ShowResourceHeaders = false;
     
     
            scheduler.SelectedDate = DateTime.Now;
     
            scheduler.MultiDayView.NumberOfDays = 2;
       scheduler.DataSource = GetAgendaItems();
    }

    Can you please see if you are using any embedded templates or embedding the control into an assembly. It seems that the RadWindow object is properly found in the control hierarchy. Can you please try to move the RadWindow and the JavaScript on the EditEventItem template level?

    All the best,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  9. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    10 Nov 2010
    Link to this post
    Hi Radoslav,

    Thanks for all your help. Moving the javascript up to the Edit Template did the trick. I am not sure why it makes a difference, but to answer your questions, my code for the custom controls are defined in a custom assembly but the resources that contained the mark up were not embedded. Any ideas?

    Also, I have another question, it seems like I am missing something about how controls should be initialized with Sitefinity SimpleControls from your response to one of the thread

    "It seems that the InitializeControls event is too early in the page/control life cycle to set the scheduler. This looses the control data and the control is rebound every time there is a postback."

    Can you explain, the page lifecycle and when certain things should be initialized. It was not obvious to be that my control was being rebound on every post back.

    Again, thank your for all your help,

    Bobby
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Nov 2010
    Link to this post
    Hello Bobby,

    The problem with back-end pages is that your controls exist in a complex hierarchy of embedded controls. These controls are added on the CreateChildControls method of the SimpleControl base class. This is why if you initialize the control in other event you might have problems.

    All the best,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    13 Nov 2010
    Link to this post
    Thanks for all your help.
Register for webinar
11 posts, 2 answered