This topic demonstrates how to create a user control and implement a Polls public control in it.
A user control could wrap an existing Poll control, and implement the custom logic. In order to do that, the user control should wrap the
PollBox class. Also, the PollId property should have an appropriate WebEditor attribute. Following is an exemplary
implementation of such a user control:
| PollsControl.ascx.cs |
Copy Code |
|
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using
System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.ComponentModel; using Telerik.Polls; using Telerik.Cms.Web.UI; using
Telerik.Polls.WebControls;
public partial class Sitefinity_UserControls_PollsControl : System.Web.UI.UserControl
{
[Themeable(false)]
[Category("Data")]
[DefaultValue("")]
[Description("Gets or sets the Polls Provider Name")]
public string ProviderName
{
get
{
return PollBox1.ProviderName;
}
set
{
PollBox1.ProviderName = value;
}
}
[Bindable(true)]
[Category("Data")]
[WebEditor("Telerik.Polls.WebControls.PollBoxEditor, Telerik.Polls")]
[Description("Gets or sets the ID of the poll which will be displayed")]
public Guid PollId
{
get
{
return this.PollBox1.PollId;
}
set
{
this.PollBox1.PollId = value;
}
}
public PollBox Poll
{
get
{
return this.PollBox1;
}
set
{
this.PollBox1 = value;
}
}
protected void Page_Load(object
sender, EventArgs e)
{
}
}
|
| PollsControl.ascx |
Copy Code |
|
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PollsControl.ascx.cs" Inherits="Sitefinity_UserControls_PollsControl" %> <%@ Register Assembly="Telerik.Polls" Namespace="Telerik.Polls.WebControls" TagPrefix="sfPolls" %>
<h2>My
Polls:</h2> <div>
<sfPolls:PollBox ID="PollBox1" runat="server"></sfPolls:PollBox> </div>
|
This is the line that should be added to the <toolboxControls> tag in the web.config file so that the user control is available in the
Toolbox in the Admin part of Sitefinity:
| web.config |
Copy Code |
|
<add name="PollsControl" section="Polls" url="~/Sitefinity/UserControls/PollsControl.ascx" />
|