More in this section

Forums / Developing with Sitefinity / Adding ListModule to User Control

Adding ListModule to User Control

7 posts, 0 answered
  1. briankb
    briankb avatar
    56 posts
    Registered:
    23 Feb 2004
    12 Feb 2008
    Link to this post
    I have a working user control that implements a generic content module. Thanks to your example code in the Developer's Manual. Could you provide an example of doing the same thing with the List Module?

    Here is the code we are using to add the generic content module to our user control.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctp.ascx.cs" Inherits="UserControls_ctp" %> 
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %> 
    <div id="ctp_Wrapper"
        <div id="ctp_Header"
            <h1><asp:label runat="server" ID="lblTitle"/></h1> 
        </div> 
        <div id="ctp_MC_Wrapper"
            <div id="ctp_Maincontent"
            <sfWeb:GenericContent runat="server" ID="GenericContent1" /> 
            </div> 
        </div> 
        <div id="ctp_Footer"
        </div> 
    </div> 

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    12 Feb 2008
    Link to this post
    Hi Brian,

    I suppose you want to implement Lists public control in a User Control. Here is a simple example how to achieve this:

    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListsControl.ascx.cs" Inherits="UserControls_ListsControl" %> 
    <%@Register Assembly="Telerik.Lists" Namespace="Telerik.Lists.WebControls" TagPrefix="sfLists" %> 
     
    <h2>My lists:</h2> 
    <div> 
        <sfLists:ListDisplay ID="ListDisplay1" runat="server"></sfLists:ListDisplay> 
    </div> 

    .cs
    using System.ComponentModel; 
    using Telerik.Lists; 
    using Telerik.Cms.Web.UI; 
     
    public partial class UserControls_ListsControl : System.Web.UI.UserControl, IListDisplay 
        private string providerName; 
     
        [Category("Data")] 
        public string ProviderName 
        { 
            get 
            { 
                if (String.IsNullOrEmpty(this.providerName)) 
                    this.providerName = ListManager.DefaultProviderName; 
                return this.providerName; 
            } 
            set 
            { 
                this.providerName = value; 
            } 
        } 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
        #region IListDisplay Members 
     
        [Category("Data")] 
        [TypeConverter("Telerik.Lists.WebControls.ListsIdsConverter, Telerik.Lists")] 
        [WebEditor("Telerik.Lists.WebControls.ListSelector, Telerik.Lists")] 
        public Guid[] ListsIds 
        { 
            get 
            { 
                return this.ListDisplay1.ListsIds; 
            } 
            set 
            { 
                this.ListDisplay1.ListsIds = value; 
            } 
        } 
        #endregion 

    Hope this is helpful for you.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. briankb
    briankb avatar
    56 posts
    Registered:
    23 Feb 2004
    12 Feb 2008
    Link to this post
    Would you mind doing the same example code for a Poll?

    I thought I could figure it out from your List example but I don't see an equivalent interface for the polls.
  4. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    15 Feb 2008
    Link to this post
    Hi Briankb,

    You are right, there isn't an exact equivalent of the ListDisplay interface for Polls. Instead, you need to wrap the PollBox class. Here is the code you asked for:

    PollsControl.ascx.cs:

    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:

    <%@ 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>  
     

    and this is the line you need to add to the <toolboxControls> tag in the web.config file:

     <add name="PollsControl" section="Polls" url="~/Sitefinity/UserControls/PollsControl.ascx" /> 


    Hope this helps.


    Kind regards,
    Sonya
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. briankb
    briankb avatar
    56 posts
    Registered:
    23 Feb 2004
    15 Feb 2008
    Link to this post
    Thank you again!

    It works great except it is too big for the container which is only 141px wide. Can it fit either through code changes/additions or a skin?
  6. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    15 Feb 2008
    Link to this post
    Hi Briankb,

    You could change the width in the .css fie of the theme you are applying to the page that displays the polls. However, we advise you to be mindful of the changes you do. If you prefer us to give you a more detailed explanation or suggestion, we would need a link to your demo site (any site on which you are testing).

    Regards,
    Sonya
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. briankb
    briankb avatar
    56 posts
    Registered:
    23 Feb 2004
    15 Feb 2008
    Link to this post
    We will for sure be sending you a ticket and link to our live dev site for this project. For the most part we have been having a great experience with SiteFinity and everyone is excited that we have a platform we can start with and design or program the custom bits for customers.

    When we are done with our customization I plan to submit a ticket with any issues and quarks, like this one with polls. So that your Telerik/SiteFinity experts can determine if it's something that can be fixed. We are hoping to have the site "done" next week and probably submit the pecklist ticket the week following that.

    Thanks for your help so far.
Register for webinar
7 posts, 0 answered