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

Forums / General Discussions / Adding Custom Controls To Form Builder

Adding Custom Controls To Form Builder

71 posts, 0 answered
  1. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jan 2011
    Link to this post
    Hi Matt,

    Actually you can format the DateTime in the get_value and set_value

    var val = (new Date(res)).format("MM/dd/yyyy");

    Kind regards,
    Ivan Dimitrov
    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
  2. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Ivan,

    Using your sample code, I can't get .Net to recognise the objects you are adding to the control - see the screenshot below.

    Please list the references I have to add to my project in order to make your sample code work.

    http://twitpic.com/3pbzpy/full
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hello Matt,

    You should use Telerik.Sitefinity which is added as a reference inside the template. Please make sure that your project has a reference to the dll from your bin folder.

    All the best,
    Ivan Dimitrov
    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
  4. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Hi Ivan,

    My project already has a reference to Telerik.Sitefinity

    Matt.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hi Matt,

    Make sure that the template build action is set as embedded resource and build the project. There is no other reference that you need to declare the control.

    All the best,
    Ivan Dimitrov
    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
  6. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Hi Ivan,

    The template build action is already set as embedded.

    Any ideas why the controls aren't being recognised?

    Visual Studio is also complaining because, for instance, "titleLabel" appears more than once.

    Matt.
  7. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Ivan,

    Could you possibly zip up your project and make it available to download - that would be far easier than cutting and pasting code into Visual Studio (and should eliminate the problems I'm facing now).

    Matt.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hi Matt,

    Do you get errors when you build? Generally you do not have intellisense in th embedded templates. Are there errors when you drop the control in a form?

    Best wishes,
    Ivan Dimitrov
    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
  9. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Hi Ivan,

    The project appears to build without any errors.

    However, I haven't got to the stage of dragging the control onto a form.

    When I copy and paste your code into my js file, I get an error after the last "}" and before the line:

    Telerik.Sitefinity.Samples.FiledControlCustom.registerClass('Telerik.Sitefinity.Samples.FiledControlCustom', Telerik.Sitefinity.Web.UI.Fields.FieldControl);

    the error is "expected identifier or string.

    Also, later in your message, you give the following code:

    set_value: function (value) {
        
        this._value = value;
      
        if (this.get_displayMode() === Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Write) {
            if (this._RadDatePicker) {
                if (value === undefined || value === null) {
                    this._RadDatePicker.clear();
                }
                else {
                    this._value = GetUserPreferences().sitefinityToLocalDate(value);
                    this._RadDatePicker.set_selectedDate(this._value);
                }
            }
        }

    Is this to replace the entire set_value function in the code above it?

    Elsewhere in the message, you say:

    "The MetaField of the control should be created manually."

    Although another forum user has posted code to do with the MetaField, it isn't clear to me where that code should go.

    That is why I think it would be far easier if you gave us access to your working project - so far I've spent many hours cutting and pasting code and trying to get it to work, when I feel that if you posted your project I could have a working example up and running in a few minutes.

    This thread was started over a month ago, and I still don't have a working example.

    The purpose of me creating this control is to convince my managing director that we should proceed to buying the enterprise version of sitefinity 4.





  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hello Matt,

    I attached a sample project that you can check. Generally most of the things here are described very well and actually in more details even if there is a help article for such a control.

    All the best,
    Ivan Dimitrov
    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. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Hi Ivan,

    Thanks for that.

    When I build the project and try to drag the new object onto a form, I get the error:

    Exception of type 'System.Web.HttpUnhandledException' was thrown.

    When adding the control to Sitefinity, I put the following in Control Type.

    Telerik.Sitefinity.Samples.FiledControlCustom

    Can you confirm if this is correct, or if something else should go in that field.

    Matt.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hi Matt,

    This is something related to the initial drop of the control. Publish the form and edit it. If you want you can use IsDesignMode to hide the control when you edit it.

    Regards,
    Ivan Dimitrov
    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
  13. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    12 Jan 2011
    Link to this post
    Thanks Ivan - publishing and then editing fixes that problem.

    Is that a bug in Sitefinity which will be fixed in the final release, or is it something to do with the custom control?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hello Matt,

    It is something to the control that I will check after the release.

    Regards,
    Ivan Dimitrov
    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
  15. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    13 Jan 2011
    Link to this post
    Hello Ivan,

    If I want to edit it after publishing, there is an exception:

    Runtime error in Microsoft JScript: 'Telerik.Sitefinity.Samples.FiledControlCustom' is null or no object

    in the following line in a dynamic file:
    $create(Telerik.Sitefinity.Samples.FiledControlCustom, {"displayMode":1}, null, {"datePicker":"C009_ctl00_C004_ctl00_RadDatePicker1"}, $get("C009_ctl00_C004"));

    I did all like you said. What went wrong? Is it possible, that the JS file won't be executed?

    Thanks in advance,
    Marcel
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hi Matt,

    The first error is thrown, because the script or its namespace is not correct for the application you use.

    1. GetScriptDescriptors should be modified as shown below

    public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
            {
                var descriptor = base.GetScriptDescriptors().First() as ScriptControlDescriptor;
                descriptor.AddElementProperty("textLabel", this.TextLabel.ClientID);
                descriptor.AddComponentProperty("datePicker", this.Picker.ClientID);
                return new[] { descriptor };
            }

    2. You should add a label that will show the date when the form is submitted from the backend

    protected internal virtual Label TextLabel
       {
           get
           {
               return this.Container.GetControl<Label>("textLabel", true);
           }
       }


    Below is the updated code

    <%@ Control Language="C#" %>
     
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
     
    <sf:ConditionalTemplateContainer ID="conditionalTemplate" runat="server">
        <Templates>
            <sf:ConditionalTemplate ID="ConditionalTemplate1" Left="DisplayMode" Operator="Equal" Right="Read" runat="server">      
                <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtLbl"></sf:SitefinityLabel>
                <sf:SitefinityLabel id="textLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtContent"></sf:SitefinityLabel>
                <sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="p" HideIfNoText="false" CssClass="sfDescription"></sf:SitefinityLabel>
                 <telerik:RadDateTimePicker ID="RadDatePicker1" runat="server" visible="false">
                        </telerik:RadDateTimePicker
      
            </sf:ConditionalTemplate>
            <sf:ConditionalTemplate ID="ConditionalTemplate2" Left="DisplayMode" Operator="Equal" Right="Write" runat="server">
                <asp:Label ID="titleLabel" runat="server" CssClass="sfTxtLbl" />
                <asp:LinkButton ID="expandButton" runat="server" OnClientClick="return false;" CssClass="sfOptionalExpander" />
                <asp:Panel ID="expandableTarget" runat="server" CssClass="sfFieldWrp">
      
                        <telerik:RadDateTimePicker ID="RadDatePicker1" runat="server">
                        </telerik:RadDateTimePicker
      
                    <sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
                    <sf:SitefinityLabel id="exampleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />
                </asp:Panel>
            </sf:ConditionalTemplate>
        </Templates>
    </sf:ConditionalTemplateContainer>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Web.UI.Fields;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Web.UI.Fields.Enums;
    using Telerik.Web.UI;
    using System.Web.UI;
    using System.ComponentModel;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
    using Telerik.Sitefinity.Metadata.Model;
    using Telerik.Sitefinity.Web.UI.Fields.Config;
    using Telerik.Sitefinity.Data.Metadata;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.Data.Metadata;
     
    namespace Telerik.Sitefinity.Samples
    {
        [FieldDefinitionElement(typeof(DateFieldElement))]
        [DatabaseMapping(UserFriendlyDataType.Date)]
        public class FiledControlCustom : FieldControl, IFormFieldControl
        {
     
            public FiledControlCustom()
            {
                this.DisplayMode = Sitefinity.Web.UI.Fields.Enums.FieldDisplayMode.Write;
            }
     
            public override FieldDisplayMode DisplayMode
            {
                get
                {
                    return base.DisplayMode;
                }
                set
                {
                    base.DisplayMode = value;
                }
            }
     
            [TypeConverter(typeof(ObjectStringConverter))]
            public override object Value
            {
                get
                {
                    var val = DateTime.Now;
                    switch (this.DisplayMode)
                    {
                        case FieldDisplayMode.Read:
                            if (Picker.SelectedDate == null)
                            {
                                val = DateTime.Now;
                            }
                            else
                            {
                                val = Picker.SelectedDate.Value;
                            }
                            break;
                        case FieldDisplayMode.Write:
                            if (Picker.SelectedDate == null)
                            {
                                val = DateTime.Now;
                            }
                            else
                            {
                                val = Picker.SelectedDate.Value;
                            }
                            break;
                    }
                    return val;
                }
                set
                {
                    if (this.ChildControlsCreated)
                    {
                        switch (this.DisplayMode)
                        {
                            case FieldDisplayMode.Write:
     
                                this.Picker.SelectedDate.Value.ToString();
                                break;
     
                            case FieldDisplayMode.Read:
                                Picker.SelectedDate.Value.ToString();
                                break;
                        }
                        this.value = null;
                    }
                    else
                    {
                        this.value = value;
                    }
                }
            }
     
     
            protected override System.Web.UI.WebControls.WebControl TitleControl
            {
                get
                {
                    return this.TitleLabel;
                }
            }
     
            protected override WebControl DescriptionControl
            {
                get
                {
                    return this.DescriptionLabel;
                }
            }
     
            /// <summary>
            /// Gets the reference to the control that represents the example of the field control.
            /// Return null if no such control exists in the template.
            /// </summary>
            /// <value></value>
            protected override WebControl ExampleControl
            {
                get
                {
                    return this.ExampleLabel;
                }
            }
     
     
            protected internal virtual Label TitleLabel
            {
                get
                {
                    return this.Container.GetControl<Label>("titleLabel", true);
                }
            }
     
            protected internal virtual Label TextLabel
            {
                get
                {
                    return this.Container.GetControl<Label>("textLabel", true);
                }
            }
     
     
            protected internal virtual Label DescriptionLabel
            {
                get
                {
                    return Container.GetControl<Label>("descriptionLabel", true);
                }
            }
     
     
            protected internal virtual Label ExampleLabel
            {
                get
                {
                    return this.Container.GetControl<Label>("exampleLabel", this.DisplayMode == FieldDisplayMode.Write);
                }
            }
     
            protected virtual RadDateTimePicker Picker
            {
                get
                {
                    return this.Container.GetControl<RadDateTimePicker>("RadDatePicker1", this.DisplayMode == FieldDisplayMode.Write);
                }
            }
     
     
            protected override void InitializeControls(Web.UI.GenericContainer container)
            {
     
                DateTime? dateValue = null;
                if (this.Value != null)
                {
                    dateValue = (DateTime)this.Value;
                }
                switch (this.DisplayMode)
                {
                    case FieldDisplayMode.Read:
     
                        break;
                    case FieldDisplayMode.Write:
     
                       this.Picker.SelectedDate = dateValue;
                            this.Picker.DateInput.DateFormat = "MM/dd/yyyy h:mm:ss tt";
                            this.Picker.SelectedDateChanged += new Telerik.Web.UI.Calendar.SelectedDateChangedEventHandler(Picker_SelectedDateChanged);
                            this.Picker.DateInput.TabIndex = this.TabIndex;
                            this.Picker.DatePopupButton.TabIndex = this.TabIndex;
                            this.Picker.TimePopupButton.TabIndex = this.TabIndex;
                            this.TabIndex = 0;
                            break;
                         
                }
            }
     
            void Picker_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
            {
                this.Value = e.NewDate;
            }
     
            protected override string LayoutTemplateName
            {
                get { return FiledControlCustom.layoutTemplateName; }
            }
     
            public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
            {
                var descriptor = base.GetScriptDescriptors().First() as ScriptControlDescriptor;
                descriptor.AddElementProperty("textLabel", this.TextLabel.ClientID);
                descriptor.AddComponentProperty("datePicker", this.Picker.ClientID);
                //descriptor.AddProperty("displayMode", this.DisplayMode);
                return new[] { descriptor };
            }
     
            public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
            {
                var scripts = new List<ScriptReference>(base.GetScriptReferences())
                                {
                                    new ScriptReference(FiledControlCustom.fieldScript, this.GetType().Assembly.FullName),
                                    new ScriptReference(FiledControlCustom.fieldDisplayModeScript, "Telerik.Sitefinity"),
                                };
                return scripts;
            }
     
            internal const string fieldScript = "Telerik.Sitefinity.Samples.Resources.FiledControlCustom.js";
            private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.FieldControlCutom.ascx";
            private const string fieldDisplayModeScript = "Telerik.Sitefinity.Web.UI.Fields.Scripts.FieldDisplayMode.js";
            private object value;
     
            #region IFormFieldControl Members
            [TypeConverter(typeof(ExpandableObjectConverter))]
            public IMetaField MetaField
            {
                get
                {
                    if (this.metaField == null)
                    {
                        this.metaField = new MetaField()
                        {
                            DBType = "DATE",
                            DBSqlType = "DATETIME",
                            DBLength = null,
                            ClrType = typeof(DateTime).FullName
                        };
                    }
                    return this.metaField;
                }
                set
                {
                    this.metaField = value;
                }
            }
     
            private IMetaField metaField = null;
     
            #endregion
        }
    }


    Type.registerNamespace("Telerik.Sitefinity.Samples");
     
    Telerik.Sitefinity.Samples.FiledControlCustom = function (element) {
     
       
        this._datePicker = null;
        this._displayMode = null;
        this._textLabel = null;
        Telerik.Sitefinity.Samples.FiledControlCustom.initializeBase(this, [element]);
    }
     
     
    Telerik.Sitefinity.Samples.FiledControlCustom.prototype =
    {
        /* --------------------------------- set up and tear down --------------------------------- */
        initialize: function () {
            Telerik.Sitefinity.Samples.FiledControlCustom.callBaseMethod(this, 'initialize');
        },
        dispose: function () {
            Telerik.Sitefinity.Samples.FiledControlCustom.callBaseMethod(this, 'dispose');
        },
     
     
        /* --------------------------------- public methods ---------------------------------- */
     
     
        reset: function () {
            this.set_value(null);
            Telerik.Sitefinity.Samples.FiledControlCustom.callBaseMethod(this, "reset");
        },
     
        // Gets the value of the field control.
        isChanged: function () {
            var thisValue = GetUserPreferences().sitefinityToUniversalDate((new Date(this._value)).format("MM/dd/yyyy h:mm:ss"));
            var oldValStr = thisValue ? thisValue.toString() : "";
            var newValue = this.get_value(); // This returns null when the date is not chosen or empty
            if (newValue == null)
                return false;
            var newValStr = newValue ? newValue.toString() : "";
            newValStr = (new Date(newValStr)).format("MM/dd/yyyy h:mm:ss");
     
            if (oldValStr == newValStr) {
                return false;
            } else {
                return true;
            }
     
        },
     
        // Gets the value of the field control.
        get_value: function () {
            if (this.get_displayMode() === Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Write) {
                var res = this._datePicker.get_selectedDate();
                if (res) {
     
                    return GetUserPreferences().sitefinityToUniversalDate(res);
                }
                else {
                    return null;
                }
            }
            return this._value;
        },
     
        // Sets the value of the field control.
        set_value: function (value) {
            this._value = value;
     
            if (this.get_displayMode() === Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Write) {
                if (this._datePicker) {
                    if (value === undefined || value === null) {
                        this._datePicker.clear();
                    }
                    else {
                        this._value = GetUserPreferences().sitefinityToLocalDate(value);
                        this._datePicker.set_selectedDate(this._value);
                    }
                }
            }
            else {
     
                if (value === undefined || value === null) {
                    if (this._textLabel) {
                        this._textLabel.innerHTML = "";
                    }
                }
                else {
                    if (Date.prototype.isPrototypeOf(value)) {
                        value = value.toLocaleDateString();
                    }
                    if (this._textLabel) {
                        this._textLabel.innerHTML = value;
                    }
                }
            }
     
            this.raisePropertyChanged("value");
            this._valueChangedHandler();
        },
     
     
     
        /* --------------------------------- event handlers ---------------------------------- */
     
        /* --------------------------------- private methods --------------------------------- */
     
        /* --------------------------------- properties -------------------------------------- */
     
        get_datePicker: function () {
            return this._datePicker;
        },
     
        set_datePicker: function (value) {
            this._datePicker = value;
        },
     
        get_textLabel: function () {
            return this._textLabel;
        },
        set_textLabel: function (value) {
            this._textLabel = value;
        }
    }
     
    Telerik.Sitefinity.Samples.FiledControlCustom.registerClass('Telerik.Sitefinity.Samples.FiledControlCustom', Telerik.Sitefinity.Web.UI.Fields.FieldControl);


    Regards,
    Ivan Dimitrov
    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
  17. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    17 Jan 2011
    Link to this post
    Hello Ivan,

    my problem's still there. I can't figure out how I can make it work.

    Regards,
    Marcel
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hi Matt,

    Have you registered the script to AssemblyInfo class ? Can you check whether the build action of the resources is "Embedded resource"

    This code runs fine. The problem is somewhere in your setup. Please follow the guidance from this tutorial

    Kind regards,
    Ivan Dimitrov
    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
  19. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    17 Jan 2011
    Link to this post
    Hello Ivan,

    my name is Marcel ;)
    Now I have copied & pasted your code above, just to make sure everything is right. Here are my current settings:
    FieldControlCustom.cs - Compile
    FieldControlCustom.js - Embedded resource
    FieldControlCustom.ascx - Embedded resource
    AssemblyInfo.cs - Compile

    Can you confirm this settings?

    Other than before there is a new message appearing. It says
    A required control was not found in the template for "Telerik.Sitefinity.Samples.Resources.FieldControlCustom.ascx". The control must be assignable form type "System.Web.UI.WebControls.Label" and must have ID "textLabel".
    in line
    return this.Container.GetControl<Label>("textLabel", true);

    What did I do wrong?

    Thanks and thanks in advance for future help,
    Marcel
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hi ,

    The error says that the control below cannot be found

    <sf:SitefinityLabel id="textLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtContent"></sf:SitefinityLabel>

    This control is not in your template or the template path is not correct in your FiledControlCustom

    Best wishes,
    Ivan Dimitrov
    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
  21. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    18 Jan 2011
    Link to this post
    Hi Ivan and Marcel,

    I was also getting this error.  I think I've fixed that, but I'm having other problems.

    I changed Ivan's code to the following:

    <%@ Control Language="C#" %>
      
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      
    <sf:ConditionalTemplateContainer ID="conditionalTemplate" runat="server">
        <Templates>
            <sf:ConditionalTemplate ID="ConditionalTemplate1" Left="DisplayMode" Operator="Equal" Right="Read" runat="server">     
                <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtLbl"></sf:SitefinityLabel>
                <sf:SitefinityLabel id="textLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtContent"></sf:SitefinityLabel>
                <sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="p" HideIfNoText="false" CssClass="sfDescription"></sf:SitefinityLabel>
                <telerik:RadDateTimePicker ID="RadDatePicker1" runat="server" visible="false"></telerik:RadDateTimePicker>
            </sf:ConditionalTemplate>
            <sf:ConditionalTemplate ID="ConditionalTemplate2" Left="DisplayMode" Operator="Equal" Right="Write" runat="server">
                <asp:Label ID="titleLabel" runat="server" CssClass="sfTxtLbl" />
                <asp:LinkButton ID="expandButton" runat="server" OnClientClick="return false;" CssClass="sfOptionalExpander" />
                <asp:Panel ID="expandableTarget" runat="server" CssClass="sfFieldWrp">
                    <telerik:RadDateTimePicker ID="RadDatePicker1" runat="server"></telerik:RadDateTimePicker>
                    <sf:SitefinityLabel id="textLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtContent"></sf:SitefinityLabel>
                    <sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
                    <sf:SitefinityLabel id="exampleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />
                </asp:Panel>
            </sf:ConditionalTemplate>
        </Templates>
    </sf:ConditionalTemplateContainer>

    Other than that, I've copied Ivan's modified code exactly.

    The attachment systemsettings.jpg shows how I've added the control to Sitefinity - Ivan, can you check that I've done this correctly.

    I get an error when I drag Ivan's control onto a form, but it looks ok if I publish and then edit the form.  See attachment draggingcontrotoform.jpg.

    When I add the form to a page, I get an error.  Again, if I publish the page and edit it, it seems fine - see attachment addingformtopage.jpg.

    When I view the page on the site, I get an error when I submit the form - see attachments errorwhensubmitting.jpg and scripterror.jpg.

    I'm sure I'm doing something wrong here, but I can't see what it is.

    Matt.


  22. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    21 Jan 2011
    Link to this post
    Any updates on this?
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Jan 2011
    Link to this post
    Hello Matt,

    The GetUserPreferences is null inside get_value function. You should check for nulls

    get_value: function () {
          if (this.get_displayMode() === Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Write) {
              var res = this._datePicker.get_selectedDate();
              if (res) {
     
                  if (typeof (GetUserPreferences) == "function") {
                      return GetUserPreferences().sitefinityToUniversalDate(res);
                  }
                  else {
                      return res;
                  }
              }
              else {
                  return null;
              }
          }
          return this._value;
      },


    Best wishes,
    Ivan Dimitrov
    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
  24. UI Crew
    UI Crew avatar
    99 posts
    Registered:
    24 Sep 2012
    31 Jan 2011
    Link to this post
    Hi,

    Has anyone figured out why you get this error when you change the properties on a custom form contro and hit save? Or is it just me that gets this error:

    Exception of type 'System.Web.HttpUnhandledException' was thrown

    Thanks,
    Seth
  25. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    02 Feb 2011
    Link to this post
    Hello Ivan,

    now I get another script error message when I'm loading the control (middle line):

    }; $create = Sys.Component.create = function(f, c, b, g, d) {
        var a = d ? new f(d) : new f;
        a.beginUpdate();

    When I try to continue or ignore many more script errors appear (i think it's a death loop).

    Thanks,
    Marcel
  26. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Feb 2011
    Link to this post
    Hello Marcel,

    Can you check the call stack of the error? The lines you pastes are from MS AJAX function and actually this is where the code fails due to wrong data passed somewhere else.

    Regards,
    Ivan Dimitrov
    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
  27. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    02 Feb 2011
    Link to this post
    Hello Ivan,

    Is there a call stack if a dynamic JavaScript exception appears? Where can I find that?

    Thanks,
    Marcel
  28. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    10 Feb 2011
    Link to this post
    Are there any updates on this thread?
  29. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2011
    Link to this post
    Hello Marcel,

    You can see the js call stack using FireBug or IE dev tools. The error you see comes from MS AJAX.

    Regards,
    Ivan Dimitrov
    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
  30. Duneel
    Duneel avatar
    166 posts
    Registered:
    08 Dec 2010
    04 Mar 2011
    Link to this post
    Hi,

    I want to inject the custom field (datepicker sample sent by Ivan) in to a custom module. Can someone tell me how to do that in the ModuleDefinitions.cs file rather than doing it through the Administration screens?

    Thanks,
    Duneel
71 posts, 0 answered
1 2 3