+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Extending PollBox and PollProvider

Extending PollBox and PollProvider

2 posts, 1 answered
  1. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    04 May 2010
    Link to this post
    Hello,

    I would like to extend the PollBox control to support other kind of visitor status check, using the logged user as the only verification, one vote per user. I found it a little difficult as I tried to extend the PollBox control and the CheckVisitorStatus() function is private, as I saw on the CreateChildControls() this is the function that check for double voting. Also the PollProvider doesnt give me the option to change the verification behavior.

    What would be the best approach here? Rewrite the entire PollBox control? Even doing that the provider interface still doesnt export the interface to this customization, should I write an entire new module from scratch?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 May 2010
    Link to this post
    Hello Augusto Radtke,

    CheckVisitorStatus denies the voting only when you set ipBlocking  property to true. If the property is false there is other boolean variable hasVoted that we set to false. This allows you to vote more than once. You could create a custom table in the database to store the username and IP of the poll. The implement a basic method that checks whether a given user has voted and disable to "Vote" button or hide the control

    sample code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Polls.WebControls;
    using Telerik.Web;
    using Telerik.Security;
    using Telerik.Polls;
    using System.Web.UI.WebControls;
     
    public class PollBoxToolboxItemCustom : ToolboxItem
    {
        public PollBoxToolboxItemCustom()
            : base(typeof(PollBoxCustomControl))
        {
            this.DisplayName = "";
            this.Description = "";
        }
    }
     
    [System.ComponentModel.ToolboxItem(typeof(PollBoxToolboxItemCustom))]
    public class PollBoxCustomControl : PollBox
    {
        public PollBoxCustomControl()
        {
     
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Polls/PollBox.ascx";
            }
     
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            if (!VerifyCurrentUserStatus(UserManager.GetCurrentUserName()))
            {
               // do not allow the user to vote.
                Button b = this.VoteButton as Button;
                b.Enabled = false;
                Label l = new Label();
                l.Text = "you do not have rights to vote!";
                Controls.Add(l);
            }
        }
     
     
        public virtual bool VerifyCurrentUserStatus(string UserName)
        {
     
            // check a custom table and if the username is added there for the same PollID, return false and do not allow the user
            // to vote - for instance diable the vote button and write a user friendly message
     
            if (this.PollId.ToString() == "" && UserName == "")
            {
               return _VerifyCurrentUserStatus = false;
            }
            return _VerifyCurrentUserStatus = true;
        }
     
        private bool _VerifyCurrentUserStatus = false;
    }


    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.
    Answered
2 posts, 1 answered