Adding Custom Controls To Form Builder
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.
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
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.
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"; 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) 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
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";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
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
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; #endregionGuys,
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,
I agree, James. That would be very helpful.
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);Hi Ivan,
Hi Peter,
Would it be possible to get a copy of the source code for your form control?
Matt.
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">Hi Matt,
<%@ 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>Hi Ivan,
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. |
|
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
Once I get that error, I get the same error as Peter when I try to access Sitefinity.
Now trying this in build 4.0.1030.0.
In this line:
[DatabaseMapping(DatabaseMapping.Date)]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;Hello Matt,
You should use UserFriendlyDataType enum in the round brackets.
All the best,
Ivan Dimitrov
the Telerik team
Hi Ivan,
That gives me the same problem - presumably I'm missing a reference, but I don't know where UserFriendlyDataType is defined.
Matt.
Hi Matt,
UserFriendlyDataType is a part of Telerik.Sitefinity.Model. Please check your project references.
Best wishes,
Ivan Dimitrov
the Telerik team
Thanks, Ivan.
Made that change, and I get the same errors that Peter and I have mentioned above (now using RC2).
Matt.
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
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>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 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);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); 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
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
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;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
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
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
Hi Ivan,
My project already has a reference to Telerik.Sitefinity
Matt.
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
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.
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.
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
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); 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
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.
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
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?
Hello Matt,
It is something to the control that I will check after the release.
Regards,
Ivan Dimitrov
the Telerik team
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$create(Telerik.Sitefinity.Samples.FiledControlCustom, "displayMode":1, null, "datePicker":"C009_ctl00_C004_ctl00_RadDatePicker1", $get("C009_ctl00_C004"));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 ; protected internal virtual Label TextLabel get return this.Container.GetControl<Label>("textLabel", true); <%@ 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);Hello Ivan,
my problem's still there. I can't figure out how I can make it work.
Regards,
Marcel
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
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".return this.Container.GetControl<Label>("textLabel", true);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
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.
Any updates on this?
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; ,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
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();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
Hello Ivan,
Is there a call stack if a dynamic JavaScript exception appears? Where can I find that?
Thanks,
Marcel
Are there any updates on this thread?
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
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
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
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
Hi Peter,
Thanks for the awesome tutorial. It's great!!
Duneel
Hi There,
Is the a stable working production version of this? I require to setup forms with datetime picker control.
Regards,
Jean Erasmus
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
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.
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 |
Hi Norman,
You can put a break point inside
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.
Sorry, double post because of site time out
Hi,
You have to add the title to your form control
public override string Title get return "MyCustomFormsControl";