In my last post, I demonstrated how to use Sitefinity's WebEditor attribute to make control property editing a bit more user friendly. I used Sitefinity's built-in CmrUrlWebEditor for this previous example.
Sitefinity comes with many more built-in WebEditors that can be used in your project.
Demo Magic / Confession
Before I proceed, I need to make a confession. I deliberately choose the CmsUrlWebEditor for my introductory WebEditor blog post because it is very easy to use. An earlier draft used the DhlIdEditor (example shown below).
DhlIdEditor isn't as easy or intuitive as CmsUrlWebEditor. During the writing process, I became mired in the specifics of DhlIdEditor, rather than the broader WebEditor concepts. Because I wanted to write an introductory article, I ditched DhlIdEditor and went with an easier WebEditor.
I'm telling this story as a warning.
Some built-in Sitefinity WebEditors have very specific usage requirements. Sometimes these requirements aren't documented. Keep in mind, these WebEditors were created for Sitefinity's internal use. Yes, you can use them in your own custom controls, but Sitefinity might have specific needs that don't match your custom control's needs. In those cases, it's best to create your own WebEditor.
Read my usage tips near the bottom of this post if you decide to proceed.
Full List of Sitefinity WebEditors
All WebEditors must implement the WebUITypeEditor class. To create the list below, I used ReSharper to find all classes that implement the WebUITypeEditor. Some of these pages do not yet have documentation.
Using Sitefinity Built-In WebEditors
Usage for these WebEditors is going to vary. Some WebEditors require specific data types (Guids). Other WebEditors require that underlying properties have specific ID's. It's not always obvious what you need to do.
If you're interested in using one of these WebEditors, my advice is to search the Sitefinity forums. If no information is available, post a new topic and ask the team for usage details.
Using the DhlIdEditor WebEditor
The DhlIdEditor (Dynamic Hyperlink Editor) lets the user select an existing Sitefinity page and returns the URL and Guid associated with the selected page. Because DhlIdEditor returns two values, it requires two underlying properties.
To use DhlIdEditor your control must have two properties called PageId and NavigateUrl. If these properties do not exist or have a different ID's, the WebEditor will not work.
Here is an example showing DhlIdEditor usage:
using System;
using System.ComponentModel;
using System.Web.UI;
using Telerik.Cms.Web.UI;
public partial class UserControls_WebEditorExample : System.Web.UI.UserControl
{
[TypeConverter("Telerik.Cms.Web.UI.GuidTypeConverter, Telerik.Cms")]
[WebEditor("Telerik.Cms.Web.UI.DhlIdEditor, Telerik.Cms")]
[DefaultValue(typeof(Guid), "00000000-0000-0000-0000-000000000000")]
public Guid PageId
{
get
{
return pageId;
}
set
{
pageId = value;
}
}
[UrlProperty]
[WebEditor("Telerik.Cms.Web.UI.DhlUrlEditor, Telerik.Cms")]
[Bindable(true)]
[DefaultValue("")]
public string NavigateUrl
{
get
{
return navigateUrl;
}
set
{
navigateUrl = value;
}
}
private Guid pageId;
private string navigateUrl;
protected void Page_Load(object sender, EventArgs e)
{
}
} Hopefully this blog post will be useful to anyone exploring the built-in Sitefinity WebEditors.
If this all proves too much trouble, you're always free to create your own WebEditor or a Control Designer. We'll look at these subjects in the next few days.