+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. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    07 Dec 2010
    Link to this post
    Is there a tutorial available to allow us to add controls to the form builder toolbox.

    I need to be able to create a control which the user can drag onto the form and which will create a field or fields in the backend database, just as the existing controls do.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    07 Dec 2010
    Link to this post
    Hi Matt,

    1. You have to create a control that inherits from FieldControl and implements IFormFieldControl

    2. You can register the control from Administration >> Settings >> Advanced >> Toolboxes >> FormControls

    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
  3. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    09 Dec 2010
    Link to this post
    I tried to do this, but ran into problems...

    I managed to create a user control and build the project without any errors.

    I then added the control to the toolbox.

    I logged into SiteFinity, created a form and tried to drag my new control onto the form.

    I got the error: 'SitefinityWebApp.MyControls.LinkPicker' is not allowed here because it does not extend class 'System.Web.UI.UserControl'.

    I went back to Visual Studio 2010 to try to rectify this.  When I rebuilt the project, I got a mass of errors.

    The project lost references to Microsoft.Practices.ServiceLocation, MySql.Data and all of the Telerik references (all had a yellow triangle beside them).

    Could I request that you produce a detailed example of how to accomplish this? - I think it's something that your customers would like to do.

    Also, why is it so easy to run into problems with lost references like this?


    Matt.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    09 Dec 2010
    Link to this post
    Hello Matt,

    Here is a sample code.  It is working fine if you drop it on a form.You have to implement the custom logic you want to have inside IntializeControls

    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;
     
    namespace Telerik.Sitefinity.Samples
    {
        public class FiledControlCustom  : FieldControl
        {
            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 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 override void InitializeControls(Web.UI.GenericContainer container)
            {
                throw new NotImplementedException();
            }
     
            protected override string LayoutTemplateName
            {
                get { return FiledControlCustom.layoutTemplateName; }
            }
     
            private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.FieldControlCutom.ascx";
        }
    }


    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
  5. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    10 Dec 2010
    Link to this post
    Hi Ivan,

    I'm not sure where  I would put that code.

    I'm following the instructions to create a widget.  The instructions say that I should create a Web User Control.

    When I do that, the cs file contains the following:

    public partial class TestControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
    }

    I can't see how to use your code in a Web User Control.

    Can you explain?

    Matt.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    10 Dec 2010
    Link to this post
    Hi Matt,

    You cannot use a user control. You have to create a custom control that inherits from FieldControl. Custom controls are compiled code components that execute on the server, expose the object model, and render markup text, such as HTML or XML, as a normal Web Form or user control does.

    Greetings,
    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
  7. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    10 Dec 2010
    Link to this post
    Thanks Ivan,

    I'm not familiar with creating custom controls.

    In particular, I'm confused by this line:

    private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.FieldControlCutom.ascx";

    Clearly, I don't have that file and I don't know what it contains or how to create it.

    Can you advise?

    Matt.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    10 Dec 2010
    Link to this post
    Hi Matt,

    In this line you specify the template that your custom filed control will use. This template has to be build as an embedded resource.

    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
  9. Coskun SUNALI
    Coskun SUNALI avatar
    7 posts
    Registered:
    16 Aug 2007
    14 Dec 2010
    Link to this post
    Hi Ivan,

    I see that you did not implement the IFormFieldControl interface even though you told in your first post that it should be implemented. Could you please share an example of how to implement it?

    BR,
    Coskun
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Dec 2010
    Link to this post
    Hello Coskun,

    The interface is used when you want to l load default values to MetaField property , based on the attribute, from the configuration mapping.

    [TypeConverter(typeof(ExpandableObjectConverter))]
           public IMetaField MetaField
           {
               get
               {
                   if (this.metaField == null)
                   {
                       this.metaField = this.LoadDefaultMetaField();
                   }
                   return this.metaField;
               }
               set
               {
                   this.metaField = value;
               }
     
           #region Private members
           private IMetaField metaField = null;
           #endregion

    when you implement the interface your class should use DatabaseMapping atrribute

    sample

    [DatabaseMapping(UserFriendlyDataType.ShortText)]

    Greetings,
    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. James Greaves
    James Greaves avatar
    25 posts
    Registered:
    21 Oct 2009
    16 Dec 2010
    Link to this post
    Guys,

    Sorry to bump this post but I am having a little look at this myself and I am still a little confused.  I want to add a fileupload to a form and I am struggling a bit with how to write a control for forms. 

    Has anybody got a complete example for me to have a look at?  Not asking for the file upload code...I will do all that, just cannot see how to put all the pieces together so if someone could chuck together some files in a zip for me to breakdown it would be mucho appreciated.

    Cheers,
  12. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    16 Dec 2010
    Link to this post
    I agree, James.  That would be very helpful.

  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    16 Dec 2010
    Link to this post
    Hello James,

    Here is a sample code of a form control

    Below is a sample code

    Note that FieldDisplayMode should be in write mode.

    publicclassFiledControlCustom : FieldControl
     
        {
     
      
     
            publicFiledControlCustom()
     
            {
     
                this.DisplayMode = Sitefinity.Web.UI.Fields.Enums.FieldDisplayMode.Write;
     
            }
     
      
     
            [TypeConverter(typeof(ObjectStringConverter))]
     
            publicoverrideobjectValue
     
            {
     
                get
     
                {
     
                    var val = DateTime.Now;
     
                    switch(this.DisplayMode)
     
                    {
     
                        caseFieldDisplayMode.Read:
     
                            if(Picker.SelectedDate == null)
     
                            {
     
                                val = DateTime.Now;
     
                            }
     
                            else
     
                            {
     
                                val = Picker.SelectedDate.Value;
     
                            }
     
                            break;
     
                        caseFieldDisplayMode.Write:
     
                            if(Picker.SelectedDate == null)
     
                            {
     
                                val = DateTime.Now;
     
                            }
     
                            else
     
                            {
     
                                val = Picker.SelectedDate.Value;
     
                            }
     
                            break;
     
                    }
     
                    returnval;
     
                }
     
                set
     
                {
     
                    if(this.ChildControlsCreated)
     
                    {
     
                        switch(this.DisplayMode)
     
                        {
     
                            caseFieldDisplayMode.Write:
     
      
     
                                this.Picker.SelectedDate.Value.ToString();
     
                                break;
     
      
     
                            caseFieldDisplayMode.Read:
     
                                Picker.SelectedDate.Value.ToString();
     
                                break;
     
                        }
     
                        this.value = null;
     
                    }
     
                    else
     
                    {
     
                        this.value = value;
     
                    }
     
                }
     
            }
     
      
     
      
     
            protectedoverrideSystem.Web.UI.WebControls.WebControl TitleControl
     
            {
     
                get
     
                {
     
                    returnthis.TitleLabel;
     
                }
     
            }
     
      
     
            protectedoverrideWebControl DescriptionControl
     
            {
     
                get
     
                {
     
                    returnthis.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  overrideWebControl ExampleControl
     
            {
     
                get
     
                {
     
                    returnthis.ExampleLabel;
     
                }
     
            }
     
      
     
      
     
            protectedinternalvirtualLabel TitleLabel
     
            {
     
                get
     
                {
     
                    returnthis.Container.GetControl<Label>("titleLabel", true);
     
                }
     
            }
     
      
     
          
     
            protectedinternalvirtualLabel DescriptionLabel
     
            {
     
                get
     
                {
     
                    returnContainer.GetControl<Label>("descriptionLabel", true);
     
                }
     
            }
     
      
     
          
     
            protectedinternalvirtualLabel ExampleLabel
     
            {
     
                get
     
                {
     
                    returnthis.Container.GetControl<Label>("exampleLabel", this.DisplayMode == FieldDisplayMode.Write);
     
                }
     
            }
     
      
     
            protectedvirtualRadDateTimePicker Picker
     
            {
     
                get
     
                {
     
                    returnthis.Container.GetControl<RadDateTimePicker>("RadDatePicker1", this.DisplayMode == FieldDisplayMode.Write);
     
                }
     
            }
     
      
     
      
     
            protectedoverridevoidInitializeControls(Web.UI.GenericContainer container)
     
            {
     
      
     
                DateTime? dateValue = null;
     
                if(this.Value != null)
     
                {
     
                    dateValue = (DateTime)this.Value;
     
                }
     
                switch(this.DisplayMode)
     
                {
     
                    caseFieldDisplayMode.Read:
     
                         
     
                        break;
     
                    caseFieldDisplayMode.Write:
     
                        this.Picker.SelectedDate = dateValue;
     
                        this.Picker.DateInput.DateFormat = "MM/dd/yyyy h:mm:ss tt";
     
                        this.Picker.SelectedDateChanged += newTelerik.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;
     
                }      
     
            }
     
      
     
            voidPicker_SelectedDateChanged(objectsender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
     
            {
     
                this.Value = e.NewDate;
     
            }
     
      
     
            protectedoverridestringLayoutTemplateName
     
            {
     
                get{ returnFiledControlCustom.layoutTemplateName; }
     
            }
     
      
     
      
     
      
     
            publicoverrideIEnumerable<ScriptDescriptor> GetScriptDescriptors()
     
            {
     
                var descriptor = newScriptControlDescriptor(this.GetType().FullName, this.ClientID);
     
                descriptor.AddComponentProperty("picker", this.Picker.ClientID);
     
                returnnew[] { descriptor };
     
            }
     
      
     
            publicoverrideIEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
     
            {
     
                var scripts = newList<ScriptReference>(base.GetScriptReferences())
     
                                {
     
                                    newScriptReference(FiledControlCustom.fieldScript, this.GetType().Assembly.FullName)
     
                                };
     
                returnscripts;
     
            }
     
      
     
            internalconststringfieldScript = "Telerik.Sitefinity.Samples.Resources.FiledControlCustom.js";
     
            privateconststringlayoutTemplateName = "Telerik.Sitefinity.Samples.Resources.FieldControlCutom.ascx";
     
            privateobjectvalue;
     
      
     
      
     
        }
     
    }

    js file

    Type.registerNamespace("Telerik.Sitefinity.Samples");
     
      
     
    Telerik.Sitefinity.Samples.FiledControlCustom = function (element) {
     
      
     
        this._picker = 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');
     
        },
     
      
     
      
     
        get_picker: function () {
     
            returnthis._picker;
     
        },
     
        set_picker: function (value) {
     
            this._picker = value;
     
        },
     
      
     
      
     
        /* --------------------------------- public methods ---------------------------------- */
     
      
     
      
     
        reset: function () {
     
            this.set_value(null);
     
            Telerik.Sitefinity.Samples.FiledControlCustom.callBaseMethod(this, "reset");
     
        },
     
      
     
        // Gets the value of the field control.
     
        get_value: function () {
     
      
     
      
     
            if(this.get_displayMode() == Telerik.Sitefinity.Samples.FiledControlCustom.FieldDisplayMode.Write) {
     
                if(val == '') {
     
      
     
                }
     
            }
     
            returnval;
     
        },
     
      
     
        // Sets the value of the text field control depending on DisplayMode.
     
        set_value: function (value) {
     
            if(this._hideIfValue != null&& this._hideIfValue == value) {
     
                if(this.get_displayMode() == Telerik.Sitefinity.Samples.FiledControlCustom.Write) {
     
      
     
                }
     
                else{
     
      
     
                }
     
            }
     
            else{
     
                if(this.get_displayMode() == Telerik.Sitefinity.Samples.FiledControlCustom.Write) {
     
      
     
                }
     
                else{
     
      
     
                }
     
            }
     
            this._value = value;
     
            this.raisePropertyChanged("value");
     
            this._valueChangedHandler();
     
        },
     
      
     
        // Returns true if the value of the field is changed
     
        isChanged: function () {
     
            if(this._value == null) this._value = "";
     
            var notChanged = (this._value == this.get_value());
     
            if(notChanged) {
     
                returnfalse;
     
            }
     
            else{
     
                returntrue;
     
            }
     
        }
     
      
     
      
     
        /* --------------------------------- event handlers ---------------------------------- */
     
      
     
        /* --------------------------------- private methods --------------------------------- */
     
      
     
        /* --------------------------------- properties -------------------------------------- */
     
    }
     
      
     
    Telerik.Sitefinity.Samples.FiledControlCustom.registerClass('Telerik.Sitefinity.Samples.FiledControlCustom', Telerik.Sitefinity.Web.UI.Fields.FieldControl);


    Greetings,
    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
  14. Peter Kinmond
    Peter Kinmond avatar
    3 posts
    Registered:
    22 May 2010
    20 Dec 2010
    Link to this post
    Hi Ivan,

    I have this code working correctly as a form control. However, when I submit the form that contains the control, the DatePicker still doesn't persist it's data to the database. I read your earlier post and implemented the IFormFieldControl interface in the form control to match what was in your example implementation. Other than adding that implementation of the MetaField property and adding the "DatabaseMapping" attribute to the class, is there anything else that needs to be added to persist data from the control?

    Thanks,
    Peter
  15. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    20 Dec 2010
    Link to this post
    Hi Peter,

    Would it be possible to get a copy of the source code for your form control?

    Matt.
  16. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    20 Dec 2010
    Link to this post
    I'm trying to create a control similar to james where you can upload a document, however the radupload select button and input do not appear, when inspecting it the type="hidden", but even removing that doesn't allow me to select my documents?? The default add / delete buttons appear as well as all my other controls.

    <input type="hidden" name="C000_ctl00_FileRadUpload_ClientState" id="C000_ctl00_FileRadUpload_ClientState">
  17. Peter Kinmond
    Peter Kinmond avatar
    3 posts
    Registered:
    22 May 2010
    21 Dec 2010
    Link to this post
    Hi Matt,

    Sure, no problem. Looks like I can't attach anything other than image files here, so would probably be easier for me just to email a zip of the files. Send me an email to peter {at} falafel.com and I'd be happy to send you the source code.

    It's pretty much exactly what was posted here by Ivan, along with a control template (ASCX file) with this content: 

    <%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" TagPrefix="sf" %>
    <asp:Label runat="server" ID="titleLabel" Text="title label"></asp:Label>
    <sf:RadDateTimePicker ID="RadDatePicker1" runat="server"></sf:RadDateTimePicker>
    <asp:Label runat="server" ID="descriptionLabel" Text="description Label"></asp:Label>
    <asp:Label runat="server" ID="exampleLabel" Text="example Label"></asp:Label>

    It's nice to have all the files together and in the right spot, though. I have the IFormFieldControl interface code commented out, as I still haven't gotten it to work and the data to persist. Let me know if you get that working - I'd love to see how you got that done.

    Enjoy,

    Peter
  18. Peter Kinmond
    Peter Kinmond avatar
    3 posts
    Registered:
    22 May 2010
    21 Dec 2010
    Link to this post
    Hi Ivan,

    I was able to get the custom control writing DateTime values correctly to the database by implementing the IFormFieldControl interface with the code you suggested. However, it sometimes causes the following error which renders the site unusable. After I see this error, I can't even view the site pages. That makes me believe that something is getting broken in the database itself. Have you ever seen this error and do you have any idea how to correct it?

    Thanks,

    Peter

    Server Error in '/' Application.

    A CLR type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is encountered as the field type in an artificial type; only Telerik.OpenAccess.TrackedList`1[[ supported at the moment.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NotSupportedException: A CLR type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is encountered as the field type in an artificial type; only Telerik.OpenAccess.TrackedList`1[[ supported at the moment.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace: 

    [NotSupportedException: A CLR type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is encountered as the field type in an artificial type; only Telerik.OpenAccess.TrackedList`1[[ supported at the moment.]
       Telerik.OpenAccess.RT.ArtificialTypeGenerator.ResolveType(String clr) +342
       Telerik.OpenAccess.RT.ArtificialTypeGenerator.BuildFields(Description desc) +420
       Telerik.OpenAccess.RT.ArtificialTypeGenerator.CreateTypes(ModuleBuilder modBuilder) +756
       Telerik.OpenAccess.RT.ArtificialTypeGenerator.Build() +281
       Telerik.OpenAccess.RT.ArtificialBase.StopGeneratingTypes() +56
       OpenAccessRuntime.metadata.MetaDataBuilder.CreateArtificialTypes(PackageMetaData[] packageMetaDataParam) +830
       OpenAccessRuntime.metadata.MetaDataBuilder.buildMetaData(DataObjectsRoot[] roots, Boolean ignoreNoClasses) +874
       OpenAccessRuntime.Relational.RelationalMetaDataBuilder.buildMetaData(DataObjectsRoot[] roots, Boolean ignoreNoClasses) +756
       OpenAccessRuntime.Relational.RelationalStorageManagerFactory..ctor(StorageManagerFactoryBuilder b) +758
       OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL() +82
    
    [OpenAccessException: System.NotSupportedException: A CLR type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is encountered as the field type in an artificial type; only Telerik.OpenAccess.TrackedList`1[[ supported at the moment.
       at Telerik.OpenAccess.RT.ArtificialTypeGenerator.ResolveType(String clr)
       at Telerik.OpenAccess.RT.ArtificialTypeGenerator.BuildFields(Description desc)
       at Telerik.OpenAccess.RT.ArtificialTypeGenerator.CreateTypes(ModuleBuilder modBuilder)
       at Telerik.OpenAccess.RT.ArtificialTypeGenerator.Build()
       at Telerik.OpenAccess.RT.ArtificialBase.StopGeneratingTypes()
       at OpenAccessRuntime.metadata.MetaDataBuilder.CreateArtificialTypes(PackageMetaData[] packageMetaDataParam)
       at OpenAccessRuntime.metadata.MetaDataBuilder.buildMetaData(DataObjectsRoot[] roots, Boolean ignoreNoClasses)
       at OpenAccessRuntime.Relational.RelationalMetaDataBuilder.buildMetaData(DataObjectsRoot[] roots, Boolean ignoreNoClasses)
       at OpenAccessRuntime.Relational.RelationalStorageManagerFactory..ctor(StorageManagerFactoryBuilder b)
       at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()]
       DynamicModule.ns.Wrapped_OpenAccessPageProvider_e574424e9bea4a09a6dccfa584093440.Initialize(String providerName, NameValueCollection config, Type managerType) +197
       Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, Type providerType, ExceptionPolicyName policy, ManagerBase`1 manager) +1477
       Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, ExceptionPolicyName policy, ManagerBase`1 manager) +63
       Telerik.Sitefinity.Data.ManagerBase`1.SetProvider(String providerName, String transactionName) +161
       Telerik.Sitefinity.Data.ManagerBase`1..ctor(String providerName, String transactionName) +131
       Telerik.Sitefinity.Modules.Pages.PageManager..ctor() +35
       Telerik.Sitefinity.Modules.Pages.PageManager..cctor() +36
    
    [TypeInitializationException: The type initializer for 'Telerik.Sitefinity.Modules.Pages.PageManager' threw an exception.]
       Telerik.Sitefinity.Modules.Pages.PageManager.GetManager(String providerName) +0
       Telerik.Sitefinity.Web.SiteMapBase.Initialize(String name, NameValueCollection attributes) +583
       Telerik.Sitefinity.Web.SiteMapBase.GetSiteMapProvider(String rootName) +248
       Telerik.Sitefinity.Web.SitefinityRoute.GetRouteData(HttpContextBase httpContext) +68
       System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +285
       System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
       System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +86
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
  19. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    22 Dec 2010
    Link to this post
    Using the same code, when I drag the control onto a form and then save the form, I get the following error:

    Server Error in '/Test001' Application.

    Invalid provider name "Default" for SitefinityMembershipProvider specified in web.config file. The name should match one of the providers configured in Sitefinity's Security.config configuration.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Configuration.ConfigurationErrorsException: Invalid provider name "Default" for SitefinityMembershipProvider specified in web.config file. The name should match one of the providers configured in Sitefinity's Security.config configuration.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [ConfigurationErrorsException: Invalid provider name "Default" for SitefinityMembershipProvider specified in web.config file. The name should match one of the providers configured in Sitefinity's Security.config configuration.]
       Telerik.Sitefinity.Security.UserManager.OnInitialized() +401
       Telerik.Sitefinity.Data.ManagerBase`1.Initialize() +623
       Telerik.Sitefinity.Data.ManagerBase`1..ctor(String providerName, String transactionName) +34
       Telerik.Sitefinity.Data.ManagerBase`1..ctor() +32
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +117
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +247
       System.Activator.CreateInstance() +88
       Telerik.Sitefinity.Data.ManagerBase`1.GetManager(String providerName, String transactionName) +120
       Telerik.Sitefinity.Security.SecurityManager.FindUserById(Guid userId, String providerName) +72
       Telerik.Sitefinity.Security.SecurityManager.VerifyAuthenticateInTheDatabase(SitefinityPrincipal principal, String loginIp, String lastLoginStamp) +219
       Telerik.Sitefinity.Security.SecurityManager.VerifyAuthenticateRequest(SitefinityPrincipal principal, String loginIp, String lastLoginStamp) +139
       Telerik.Sitefinity.Security.SecurityManager.AuthenticateRequest(HttpContextBase context) +537
       Telerik.Sitefinity.Web.SitefinityHttpModule.Context_AuthenticateRequest(Object sender, EventArgs e) +104
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +182
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +256
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
  20. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    22 Dec 2010
    Link to this post
    Once I get that error, I get the same error as Peter when I try to access Sitefinity.
  21. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    23 Dec 2010
    Link to this post
    Now trying this in build 4.0.1030.0.

    In this line:

    [DatabaseMapping(DatabaseMapping.Date)]

     The word DatabaseMapping inside the squared brackets is underlined in red, and I'm getting the error: The name 'DatabaseMapping' does not exist in the current context 

    I'm including the following:

    using System.Text;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Web.UI.Fields.Enums;
    using System.ComponentModel;
    using Telerik.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    using Telerik.Sitefinity.Modules.Forms;
    using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
    using Telerik.Sitefinity.Metadata.Model;
    using Telerik.Sitefinity.Data.Metadata;
    using Telerik.Sitefinity;

    I understood that the enum DatabaseMapping was defined in Telerik.Sitefinity (in Telerik.Sitefinity.dll) - has this changed?
  22. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    23 Dec 2010
    Link to this post
    Hello Matt,

    You should use UserFriendlyDataType enum in the round brackets.

    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
  23. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    23 Dec 2010
    Link to this post
    Hi Ivan,

    That gives me the same problem - presumably I'm missing a reference, but I don't know where UserFriendlyDataType is defined.

    Matt.
  24. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    23 Dec 2010
    Link to this post
    Hi Matt,

    UserFriendlyDataType  is a part of Telerik.Sitefinity.Model. Please check your project references.

    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
  25. Matt
    Matt avatar
    48 posts
    Registered:
    25 Oct 2010
    23 Dec 2010
    Link to this post
    Thanks, Ivan.

    Made that change, and I get the same errors that Peter and I have mentioned above (now using RC2).

    Matt.
  26. Peter Kinmond
    Peter Kinmond avatar
    11 posts
    Registered:
    22 Dec 2010
    06 Jan 2011
    Link to this post
    Hi Ivan,

    I have the custom DatePicker widget (with code from this thread) working correctly. When I add it to a form, and put that form on a page, it will save the results to the database correctly, which are then viewable from the "Responses" screen in the admin (see screenshot1). However, when I manually "Create a Response" from the forms page for a given form, it doesn't save the results to the database (see screenshot2). Is there something else that needs to be implemented to get a custom form widget to persist data from the "Create a Response" page? It seems to be an issue with the javascript that was provided in this thread.

    Thanks,

    Peter
  27. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    06 Jan 2011
    Link to this post
    Hello,

    Here is a working sample of the control

    1. Control Template

    <%@ 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">
                        </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>


    2. Control

    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;
            }
     
            [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 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 = new ScriptControlDescriptor(this.GetType().FullName, this.ClientID);
                descriptor.AddComponentProperty("picker", this.Picker.ClientID);
                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
        }
    }


    The MetaField of the control should be created manually.

    With the code above you will be able to publish from the front end. You cannot publish from the backend, because you need to modify and complete the javascript of the control. I made small changes to the script of the control, but it is still not completed. There should be an instance of the RadDateTime picker passed to the client and using the client side API of the RadDateTime picker you can pass the value back to the form.

    Type.registerNamespace("Telerik.Sitefinity.Samples");
     
    Telerik.Sitefinity.Samples.FiledControlCustom = function (element) {
     
       // this._picker = null;
        this._datePicker = 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');
        },
     
     
        get_picker: function () {
            return this._picker;
        },
        set_picker: function (value) {
            this._picker = value;
        },
     
     
        /* --------------------------------- public methods ---------------------------------- */
     
     
        reset: function () {
            this.set_value(null);
            Telerik.Sitefinity.Samples.FiledControlCustom.callBaseMethod(this, "reset");
        },
     
        // 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 text field control depending on DisplayMode.
        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 (this.get_displayMode() == Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Write) {
     
                }
                else {
     
                }
            }
            this._value = value;
            this.raisePropertyChanged("value");
            this._valueChangedHandler();
        },
     
        // Returns true if the value of the field is changed
        isChanged: function () {
            if (this._value == null) this._value = "";
            var notChanged = (this._value == this.get_value());
            if (notChanged) {
                return false;
            }
            else {
                return true;
            }
        },
     
     
        /* --------------------------------- event handlers ---------------------------------- */
     
        /* --------------------------------- private methods --------------------------------- */
     
        /* --------------------------------- properties -------------------------------------- */
         
        get_datePicker: function () {
            return this._datePicker;
        },
     
        set_datePicker: function (value) {
            this._datePicker = value;
        },
    }
     
    Telerik.Sitefinity.Samples.FiledControlCustom.registerClass('Telerik.Sitefinity.Samples.FiledControlCustom', Telerik.Sitefinity.Web.UI.Fields.FieldControl);


    The value should be set inside set_value function. You need to create an instance of the RadDateTime picker

    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);
                }
            }
        }


    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
  28. Peter Kinmond
    Peter Kinmond avatar
    11 posts
    Registered:
    22 Dec 2010
    07 Jan 2011
    Link to this post
    Hi Ivan,

    Thanks for the quick response. I used your sample code and it works well. It's now publishing to the backend as well as the front end (see attached screenshot). However, it only seems to be publishing the default (current) datetime, which means there's an issue with one of the Javascript functions. You mentioned the "set_value" function needs to be set. Does "set_value" need to be called from anywhere else in the JS file? Are there any other Javascript functions that need to be set which aren't listed in your code sample below? Also, which client side API calls from the RadDateTime picker allow you to pass the value back to the form?

    Thanks again for all your help.

    Peter
  29. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    07 Jan 2011
    Link to this post
    Hello Matt,

    Inside the javascript you work with the RadDateTimePicker Client Object its method and properties. In the code I am returning DateTime.Now; when there is no selected date.

    The problem here is that DisplayMode is null on the client. Override DisplayMode and send it on the client by using GetScriptDescriptors()

    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
  30. Peter Kinmond
    Peter Kinmond avatar
    11 posts
    Registered:
    22 Dec 2010
    09 Jan 2011
    Link to this post
    Hi Ivan,

    Thanks for all your help. I have the custom DatePicker widget successfully publishing in the backend now. I'm using a DatePicker, and only want to store the Date (and not the Time). I'm using the following MetaField settings to force that:

    this.metaField = new MetaField()
    {
        DBType = "DATE",
        DBSqlType = "DATE",
        DBLength = null,
        ClrType = typeof(System.DateTime).FullName,
        // Add unique field name
        FieldName = "FormDatePicker_" + this.ClientID
    };

    In the DB, the value is stored correctly as a DATE type. However, in the "Responses" screen in the Sitefinity Admin, the values are showing up as DateTime type, with a timezone offset (see screenshot). Is there a way to control the format of the display in the "Responses" screen? I'd like them to display the same way as the "SUBMITTED ON" column displays, with a date and no time.

    Thanks again,
    Peter
71 posts, 0 answered
1 2 3