Adding Custom Controls To Form Builder

Posted by Community Admin on 03-Aug-2018 13:32

Adding Custom Controls To Form Builder

All Replies

Posted by Community Admin on 07-Dec-2010 00:00

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.

Posted by Community Admin on 07-Dec-2010 00:00

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

Posted by Community Admin on 09-Dec-2010 00:00

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.

Posted by Community Admin on 09-Dec-2010 00:00

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

Posted by Community Admin on 10-Dec-2010 00:00

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.

Posted by Community Admin on 10-Dec-2010 00:00

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

Posted by Community Admin on 10-Dec-2010 00:00

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.

Posted by Community Admin on 10-Dec-2010 00:00

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

Posted by Community Admin on 14-Dec-2010 00:00

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

Posted by Community Admin on 14-Dec-2010 00:00

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

Posted by Community Admin on 16-Dec-2010 00:00

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,

Posted by Community Admin on 16-Dec-2010 00:00

I agree, James.  That would be very helpful.

Posted by Community Admin on 16-Dec-2010 00:00

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

Posted by Community Admin on 20-Dec-2010 00:00

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

Posted by Community Admin on 20-Dec-2010 00:00

Hi Peter,

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

Matt.

Posted by Community Admin on 20-Dec-2010 00:00

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">

Posted by Community Admin on 21-Dec-2010 00:00

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

Posted by Community Admin on 21-Dec-2010 00:00

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

Posted by Community Admin on 22-Dec-2010 00:00

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

Posted by Community Admin on 22-Dec-2010 00:00

Once I get that error, I get the same error as Peter when I try to access Sitefinity.

Posted by Community Admin on 23-Dec-2010 00:00

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?

Posted by Community Admin on 23-Dec-2010 00:00

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

Posted by Community Admin on 23-Dec-2010 00:00

Hi Ivan,

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

Matt.

Posted by Community Admin on 23-Dec-2010 00:00

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

Posted by Community Admin on 23-Dec-2010 00:00

Thanks, Ivan.

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

Matt.

Posted by Community Admin on 06-Jan-2011 00:00

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

Posted by Community Admin on 06-Jan-2011 00:00

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

Posted by Community Admin on 07-Jan-2011 00:00

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

Posted by Community Admin on 07-Jan-2011 00:00

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

Posted by Community Admin on 09-Jan-2011 00:00

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

Posted by Community Admin on 10-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

Hi Ivan,

My project already has a reference to Telerik.Sitefinity

Matt.

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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.

Posted by Community Admin on 12-Jan-2011 00:00

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.

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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.





Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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.

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 12-Jan-2011 00:00

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?

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 13-Jan-2011 00:00

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

Posted by Community Admin on 17-Jan-2011 00:00

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

Posted by Community Admin on 17-Jan-2011 00:00

Hello Ivan,

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

Regards,
Marcel

Posted by Community Admin on 17-Jan-2011 00:00

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

Posted by Community Admin on 17-Jan-2011 00:00

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

Posted by Community Admin on 17-Jan-2011 00:00

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

Posted by Community Admin on 18-Jan-2011 00:00

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.

Posted by Community Admin on 21-Jan-2011 00:00

Any updates on this?

Posted by Community Admin on 21-Jan-2011 00:00

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

Posted by Community Admin on 31-Jan-2011 00:00

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

Posted by Community Admin on 02-Feb-2011 00:00

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

Posted by Community Admin on 02-Feb-2011 00:00

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

Posted by Community Admin on 02-Feb-2011 00:00

Hello Ivan,

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

Thanks,
Marcel

Posted by Community Admin on 10-Feb-2011 00:00

Are there any updates on this thread?

Posted by Community Admin on 10-Feb-2011 00:00

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

Posted by Community Admin on 04-Mar-2011 00:00

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

Posted by Community Admin on 07-Mar-2011 00:00

Hi Duneel,

You need to create a FieldControlDefinitionElement where you return DefaultFieldType - your custom control that inherits from FieldControl. Please check our Products sample catalog.

Best wishes,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 15-Mar-2011 00:00

Hi Ivan,

I've written a tutorial using the code from this thread which goes into more detail about all the parts of creating a custom form control:

http://blog.falafel.com/blogs/peterkinmond/11-03-14/Creating_Custom_Form_Controls_in_Sitefinity_4_0.aspx

Thanks,

Peter

Posted by Community Admin on 15-Mar-2011 00:00

Hi Peter,

Thanks for the awesome tutorial. It's great!!

Duneel

Posted by Community Admin on 18-Mar-2011 00:00

Hi There,

Is the a stable working production version of this? I require to setup forms with datetime picker control.

Regards,
Jean Erasmus

Posted by Community Admin on 18-Mar-2011 00:00

Hi Jean,

You can use the code from the forum and polish it and Peter's solution which is very detailed ( thanks Peter)

Greetings,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 29-Jul-2011 00:00

Does anybody have a sample project that has an upload control working successfully? If so I would love to see how you went about making it happen. 

Posted by Community Admin on 11-Nov-2011 00:00

Hi,

We also have the same problem, same code that provided by this thread.  Just to provide more detail of the problem:

1.  If you just drag the datepicker control in the form the first time, and edit it (e.g., add text to title, example), there is no problem and work fine.
2.  Once the form saved, any subsequent edit, even without touching any properties in datepicker control, just to save it, and this will throw an error as below:

"

Server Error in '/' Application.


Key cannot be null.
Parameter name: key

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.ArgumentNullException: Key cannot be null.
Parameter name: key

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:

[ArgumentNullException: Key cannot be null.

Parameter name: key]

   System.Collections.Specialized.ListDictionary.get_Item(Object key) +7949573

   System.ComponentModel.PropertyDescriptorCollection.Find(String name, Boolean ignoreCase) +141

   Telerik.Sitefinity.Model.DataExtensions.SetValue(IDynamicFieldsContainer dataItem, String fieldName, Object value) +74

   Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl.SaveFormEntry(FormDescription description) +564

   Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl.ProcessForm(FormDescription form) +142

   System.EventHandler.Invoke(Object sender, EventArgs e) +0

   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691


"
3.  The error caused the form not useable, crashed the form.  You have to recreate the form without the datepicker to get it back to work again.
4.  During the troubleshooting, I noticed that the first time you drag the datepicker control in the form, the field displayed normal (small field box, see first picture of attached file), but any subsequent edit, you will notice the datepicker field got expanded or displayed with large box (see 2nd picture attached), then save, and the problem.  What is changing that?  And that could be the root cause?

Please shed some light, thanks!

Posted by Community Admin on 14-Nov-2011 00:00

Hi Norman,

You can put a break point inside

  • Value
  • InitializeControls
  • SelectedDateChanged
to see what is set when you try to save the control. It looks like that there is an empty data that goes to SetValue when you try to sav ethe form.

Here is the code that is inside SetFormEntry. The problem is in the value that is passed to the highlighted line. You can put this method in your FormsControl and call it to see what exactly is going on.

protected void SaveFormEntry(FormDescription description)
       
            var manager = FormsManager.GetManager();
            FormEntry entry = manager.CreateFormEntry(String.Format("0.1", manager.Provider.FormsNamespace, description.Name));

            foreach (IFormFieldControl formFieldControl in this.formFieldControls)
           
                var field = formFieldControl as FieldControl;

                var value = field.Value;

                if (value is List<string>)
               
                    var cnv = new StringArrayConverter();
                    var v = cnv.ConvertTo((value as List<string>).ToArray(), typeof(string));
                    entry.SetValue(formFieldControl.MetaField.FieldName, v);
               
                else
               
                    entry.SetValue(formFieldControl.MetaField.FieldName, value);
               
           

            entry.IpAddress = this.Page.Request.UserHostAddress;
            entry.SubmittedOn = DateTime.UtcNow;
            entry.UserId = SecurityManager.GetCurrentUser().UserId;
            if (AppSettings.CurrentSettings.Multilingual)
           
                entry.Language = CultureInfo.CurrentUICulture.Name;
           
            // TODO: find better way to keep autoincrement numbres in OA
            this.FormData.FormEntriesSeed++;
            entry.ReferralCode = this.FormData.FormEntriesSeed.ToString();
            manager.SaveChanges();
       
Best wishes,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 26-Apr-2012 00:00

I tried to implement Peter's code and it works great, up to a point. I can enter data in the textbox and submit and the values are showing up in the database, but when I try to view the responses in the backend, I get an "Object reference not set to an instance of an object." Here's the top of the error:
[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.<GetScriptDescriptors>d__0.MoveNext()System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
Telerik.Sitefinity.Modules.Forms.Web.UI.FormsMasterDetailView.GetScriptDescriptors()
System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl)
System.Web.UI.ScriptManager.RegisterScriptDescriptors(IScriptControl scriptControl)
Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.ViewBase.Render(HtmlTextWriter writer)
I'm using Sitefinity 5.0. I'm not sure if that makes a difference or not but thought I should mention it.

Posted by Community Admin on 26-Apr-2012 00:00

Sorry, double post because of site time out

Posted by Community Admin on 30-Apr-2012 00:00

Hi,

You have to add the title to your form control

public override string Title
       
           get
           
               return "MyCustomFormsControl";
           
       


Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed