Expose SpamProtector (Captcha) as a public property of a ContentView based control

Expose SpamProtector (Captcha) as a public property of a ContentView based control

Posted on March 01, 2010 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

Each ContentView based control represents content items that have been created from the backend or programmatically. The ContentView based control has two modes

  • List - shows all items as a list.
  • Details - shows a single item from the list.

Build-in ContentView based controls are - EventsView, BlogPosts, NewsView, ContentView control, ImageGalley, DownloadList. The last two controls are ContentView based, but they have different presentation modes, because they are supposed to show data from Images and Documents module.

For each ContentView control you can enable comments. Enabling comments can be done through the control's Advanced/Properties tab where you will find Comments section. Once you have enabled the comments you may need to protect the form from online spammers. By default, SpamProtection is not enabled on Sitefinity comment. There is no public property that you can use to do this. Since 3.6 Sitefinity uses embedded templates, so first you need to map external template - ListPageDetails.ascx, then you need to find the SpamPropector declaration at the bottom of the template and enable SpamProtector control. You can save all these steps by creating a simple control that inherits from one of the ContentView based control and expose an user friendly public property. Then you only have to use this control instead of the built-in and set the custom property from the control designer.

1. Create a custom control that inherits from BlogPosts( or another ContentView based control). 

2. Override SingleItemTemplatePath and ItemListTemplatePath properties where you need to set the path to external templates that the control will use in List and Details mode.

3. Create a ViewState property of Boolean type (true/false) that you will use in the control designer. You can set Category and Description of this property, so that you can find it easily under Advanced/Properties tab. All properties that do not have Category set are added under Misc section.

4. Crete a control references to RadEditor and SpamPropector controls. You can find the controls from the control's SingleContainer.

5. Override CreateSingleContent method, set the RadEditor as visible and check the value of the custom property - ShowCaptcha.

public class BlogPostsCustomControl : BlogPosts
{
    public BlogPostsCustomControl()
    {
    }
     public override string  SingleItemTemplatePath
     {
     get
        {
            return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
        }
     
     }
 
    public override string  ItemListTemplatePath
    {
        get
        {
         return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
        }
    }
 
 
    public virtual bool ShowCaptcha
    {
        get
        {
            object obj = ViewState["ShowCaptcha"];
            if (obj != null)
                return (bool)obj;
            return true;
        }
        set
        {
            ViewState["ShowCaptcha"] = value;
        }
    }
  
 
    protected override void CreateSingleContent()
    {
        base.CreateSingleContent();
        Editor.Visible = true;
 
        if (ShowCaptcha)
        {
            Captcha.EnableCaptcha = true;
            Captcha.Visible = true;
        }
        else
        {
            Captcha.Visible = false;
        }
    }
 
 
    protected virtual SpamProtector Captcha
    {
 
        get
        {
 
            return ((Telerik.Web.UI.SpamProtection.SpamProtector)((Telerik.Blogs.WebControls.BlogCommentsList)(this.SingleContainer.CommentsListCtrl)).Controls[0].FindControl("spamProtector"));
 
        }
 
    }
 
    protected virtual RadEditor Editor
    {
        get
        {
           return ((Telerik.Blogs.WebControls.BlogCommentsList)(this.SingleContainer.CommentsListCtrl)).Controls[0].FindControl("commentTxt") as RadEditor;
        }
    }
 
}
progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation