Creating the Submit testimonial view control designer
Creating the custom control
To create the class for the view, perform the following.
-
From the context menu of folder ControlDesigners, click Add » Class...
-
In the Name input field, enter SubmitTestimonialDesigner.
-
Open the file in Visual Studio and add the following namespaces:
using System.Collections.Generic;
using System.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
-
Change the class definition to:
public class SubmitTestimonialDesigner : ControlDesignerBase
{
}
-
Save the file.
Creating the template
To create the template of the designer view, perform the following:
-
In the context menu of folder ControlDesigners, click Add » Class...
-
In the Name input field, enter SubmitTestimonialDesignerTemplate.ascx and click Add.
-
Open the newly created file and clear its content.
-
Define the markup by pasting the following code:
<div class="sfContentViews">
<div id="RotatorOptions">
<div>
<div id="groupSettingPageSelect">
<ul class="sfTargetList">
<li>
<label for="AutoPublish" class="sfTxtLbl">Auto-Publish Testimonials</label>
<input type="checkbox" id="AutoPublish" />
</li>
</ul>
</div>
</div>
</div>
</div>
-
Save the file.
In the markup, you define a field for controlling whether to auto publish the testimonial.
Implementing the ControlDesignerBase class
To implement the ControlDesignerBase class in SubmitTestimonialDesigner.cs, perform the following:
-
Reference the embedded template by pasting the following code into SubmitTestimonialDesigner.cs:
private string _layoutTemplatePath = "~/Modules/Testimonials/ControlDesigners/SubmitTestimonialDesignerTemplate.ascx";
public override string LayoutTemplatePath
{
get { return _layoutTemplatePath; }
set { _layoutTemplatePath = value; }
}
protected override string LayoutTemplateName
{
get { return null; }
}
-
Override the InitializeControls method by pasting the following code:
protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
{
base.DesignerMode = ControlDesignerModes.Simple;
}
-
Save the file.
Implementing the client component
You must store the client class in a javascript file in the project, where the view resides.
To create the file, perform the following:
-
In the context menu of folder ControlDesigners, click Add » New Item...
-
In the left pane, select Visual C# Items » Web.
-
Click JScript File and in the Name input field, enter SubmitTestimonialDesigner.
-
Open the newly created file.
-
Add the following code to it:
Type.registerNamespace("SitefinityWebApp.Modules.Testimonials.ControlDesigners");
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner = function (element) {
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner.initializeBase(this, [element]);
}
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner.prototype = {
initialize: function () {
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner.callBaseMethod(this, 'initialize');
},
dispose: function () {
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner.callBaseMethod(this, 'dispose');
},
refreshUI: function () {
var data = this._propertyEditor.get_control();
jQuery("#AutoPublish").attr('checked', data.AutoPublish);
},
applyChanges: function () {
var controlData = this._propertyEditor.get_control();
controlData.AutoPublish = jQuery("#AutoPublish").attr('checked');
}
}
SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner.registerClass('SitefinityWebApp.Modules.Testimonials.ControlDesigners.SubmitTestimonialDesigner', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
-
Save the file.
For more information, see Working with control designers.
Referencing the client script
You must reference the client component from the view class. You do this in the override for the GetScriptReferences method. In it you must create a script reference for your client component. When creating the reference, you must specify the name of the embedded resource that contains the client component and the assembly it resides in. The name of the resource follows the same naming conventions as the name of the template.
private string _scriptPath = "~/Modules/Testimonials/ControlDesigners/SubmitTestimonialDesigner.js";
public string DesignerScriptPath
{
get { return _scriptPath; }
set { _scriptPath = value; }
}
public override IEnumerable<ScriptReference> GetScriptReferences()
{
var scripts = base.GetScriptReferences() as List<ScriptReference>;
if (scripts == null) return base.GetScriptReferences();
scripts.Add(new ScriptReference(DesignerScriptPath));
return scripts.ToArray();
}