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

Forums / Developing with Sitefinity / Custom Widget Public Property Problem

Custom Widget Public Property Problem

1 posts, 0 answered
  1. Brian
    Brian avatar
    26 posts
    Registered:
    12 Jun 2015
    06 Apr
    Link to this post

    I have made other custom controls, and never had this problem.  I just cannot see where I went wrong. We are using SF 7.3

    I have  a custom widget and one of the public properties is not being propogated to the control from the designer.  I can set the property in the designer and it remains set so that the next time I go into the designer it will have the correct value.  However, when I view the control, the property never gets set.  The code for the control is below.  I cut out a lot of the markup and code for the client control because they are large.  The cut code never gets executed right now and so the cut markup is never affected.

    If anyone can give me an idea of what the problem is, I would really appreicate the help.

    Designer Markup file

    <%@ Control %>
    <%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" %>
    <%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sfFields" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity, Version=7.3.5610.0, Culture=neutral, PublicKeyToken=b28c218413bdf563" %>
    <%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" %>
     
    <sitefinity:ResourceLinks ID="resourcesLinks" runat="server">
        <sitefinity:ResourceFile Name="Styles/Ajax.css" />
    </sitefinity:ResourceLinks>
    <div id="designerLayoutRoot" class="sfContentViews" style="min-height: 400px; overflow: auto; ">
        <ol>
            <li class="sfFormCtrl" style="display: none !important; visibility: hidden !important;">
                <asp:Label runat="server" AssociatedControlID="DiscussionGroupIdList" CssClass="sfTxtLbl">Discussion Type</asp:Label>
                <asp:RadioButtonList ID="DiscussionTypes" runat="server" CssClass="sfRadioList" >
                    <Items>
                        <asp:ListItem Text="Connect" Value="MYTENETCONNECT" Selected="True" />
                    </Items>
                </asp:RadioButtonList>
                <div class="sfExample">The image URL</div>
            </li>
            <li class="sfFormCtrl">
                <asp:Label runat="server" AssociatedControlID="DiscussionGroupIdList" CssClass="sfTxtLbl">Group</asp:Label>
                <asp:DropDownList ID="DiscussionGroupIdList" runat="server" CssClass="sfDropDown" />
                <div class="sfExample">The group discussion to be displayed</div>
            </li>
        </ol>
    </div>

    Designer CS file

    using System.Collections.Generic;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using SitefinityWebApp.Connect.Control;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Web.UI.ControlDesign;
     
    namespace SitefinityWebApp.GroupDiscussion.Designer
    {
        /// <summary>
        /// Represents a designer for the <typeparamref name="SitefinityWebApp.GroupDiscussion.GroupDiscussion"/> widget
        /// </summary>
        public class GroupDiscussionDesigner : ControlDesignerBase
        {
            /// <summary>
            /// Obsolete. Use LayoutTemplatePath instead.
            /// </summary>
            protected override string LayoutTemplateName => string.Empty;
     
            /// <summary>
            /// Gets the layout template's relative or virtual path.
            /// </summary>
            public override string LayoutTemplatePath
            {
                get { return string.IsNullOrEmpty(base.LayoutTemplatePath) ? layoutTemplatePath : base.LayoutTemplatePath; }
                set { base.LayoutTemplatePath = value; }
            }
     
            protected override HtmlTextWriterTag TagKey => HtmlTextWriterTag.Div;
     
            /// <summary>
            /// Gets the control that is bound to the Message property
            /// </summary>
            protected virtual RadioButtonList DiscussionTypes => Container.GetControl<RadioButtonList>("DiscussionTypes", true);
     
            protected virtual DropDownList DiscussionGroupIdList => Container.GetControl<DropDownList>("DiscussionGroupIdList", true);
     
            protected override void InitializeControls(GenericContainer container)
            {
                var forums = TopicRepository.GetForums( DiscussionTypes.SelectedItem.Value );
                DiscussionGroupIdList.DataSource = forums;
                DiscussionGroupIdList.DataValueField = "Id";
                DiscussionGroupIdList.DataTextField = "Title";
                DiscussionGroupIdList.DataBind();
            }
     
            /// <summary>
            /// Gets a collection of script descriptors that represent ECMAScript (JavaScript) client components.
            /// </summary>
            public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
            {
                var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
                var descriptor = (ScriptControlDescriptor)scriptDescriptors.Last();
                descriptor.AddElementProperty("groupId", DiscussionTypes.ClientID);
                descriptor.AddElementProperty("groupType", DiscussionGroupIdList.ClientID);
                return scriptDescriptors;
            }
     
            /// <summary>
            /// Gets a collection of ScriptReference objects that define script resources that the control requires.
            /// </summary>
            public override IEnumerable<ScriptReference> GetScriptReferences()
            {
                var scripts = new List<ScriptReference>(base.GetScriptReferences()) {new ScriptReference(scriptReference)};
                return scripts;
            }
            public static readonly string layoutTemplatePath = "~/CustomControls/GroupDiscussion/Designer/GroupDiscussionDesigner.ascx";
            public const string scriptReference = "~/CustomControls/GroupDiscussion/Designer/GroupDiscussionDesigner.js";
        }
    }

    Designer JS File

    Type.registerNamespace("SitefinityWebApp.GroupDiscussion.Designer");
     
    SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner = function (element) {
        /* Initialize Message fields */
        this._groupId = null;
        this._groupType = null;
     
        $("#RadWindowWrapper_PropertyEditorDialog").css("width", "auto");
        $("#RadWindowWrapper_PropertyEditorDialog").css("height", "auto");
        /* Calls the base constructor */
        SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner.initializeBase(this, [element]);
    };
     
    SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner.prototype = {
        /* --------------------------------- set up and tear down --------------------------------- */
        initialize: function() {
            /* Here you can attach to events or do other initialization */
            $("#RadWindowWrapper_PropertyEditorDialog").css("width", "auto");
            $("#RadWindowWrapper_PropertyEditorDialog").css("height", "auto");
            SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner.callBaseMethod(this, 'initialize');
        },
        dispose: function() {
            /* this is the place to unbind/dispose the event handlers created in the initialize method */
            SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner.callBaseMethod(this, 'dispose');
        },
     
        /* --------------------------------- public methods ---------------------------------- */
     
        findElement: function(id) {
            var result = jQuery(this.get_element()).find("#" + id).get(0);
            return result;
        },
     
        /* Called when the designer window gets opened and here is place to "bind" your designer to the control properties */
        refreshUI: function() {
            var controlData = this._propertyEditor.get_control();
            /* JavaScript clone of your control - all the control properties will be properties of the controlData too */
            /* RefreshUI Message */
            jQuery(this.get_groupId()).val(controlData.GroupId);
            jQuery(this.get_groupType()).val(controlData.GroupType);
        },
     
        /* Called when the "Save" button is clicked. Here you can transfer the settings from the designer to the control */
        applyChanges: function() {
            var controlData = this._propertyEditor.get_control();
     
            /* ApplyChanges Message */
            controlData.GroupId = jQuery(this.get_groupId()).val();
            controlData.GroupType = jQuery(this.get_groupType()).val();
     
        },
     
        /* --------------------------------- event handlers ---------------------------------- */
     
        /* --------------------------------- private methods --------------------------------- */
     
        /* --------------------------------- properties -------------------------------------- */
     
        /* Message properties */
        get_groupId: function() { return this._groupId; },
        set_groupId: function(value) { this._groupId = value; },
        get_groupType: function() { return this._groupType; },
        set_groupType: function(value) { this._groupType = value; }
    };
     
    SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner.registerClass('SitefinityWebApp.GroupDiscussion.Designer.GroupDiscussionDesigner', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);

    Control CS file

    namespace SitefinityWebApp.GroupDiscussion
    {
        using System;
        using System.Collections.Generic;
        using System.Globalization;
        using System.Linq;
        using System.Web.UI;
        using System.Web.UI.HtmlControls;
        using System.Web.UI.WebControls;
        using Telerik.Sitefinity.Security;
        using Telerik.Sitefinity.Web.UI;
        using Telerik.Web.UI;
     
        using Designer;
     
        /// <summary>
        /// Class used to create custom page widget
        /// </summary>
        /// <remarks>
        /// If this widget is a part of a Sitefinity module,
        /// you can register it in the site's toolbox by adding this to the module's Install/Upgrade method(s):
        /// initializer.Installer
        ///     .Toolbox(CommonToolbox.PageWidgets)
        ///         .LoadOrAddSection(SectionName)
        ///             .SetTitle(SectionTitle) // When creating a new section
        ///             .SetDescription(SectionDescription) // When creating a new section
        ///             .LoadOrAddWidget<GroupDiscussion>("GroupDiscussion")
        ///                 .SetTitle("MyTenetCustomContent")
        ///                 .SetDescription("MyTenetCustomContent")
        ///                 .LocalizeUsing<ModuleResourceClass>() //Optional
        ///                 .SetCssClass(WidgetCssClass) // You can use a css class to add an icon (Optional)
        ///             .Done()
        ///         .Done()
        ///     .Done();
        /// </remarks>
        [Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(GroupDiscussionDesigner))]
        public class GroupDiscussion : SimpleView
        {
            private bool _isFilter;
            private const int PageSize = 5;
     
            /// <summary>
            /// Gets or sets the Id for the Discussion Group being interacted with.
            /// </summary>
            public Guid GroupId { get; set; }
     
            public string GroupType { get; set; }
     
            protected ScriptManager ScriptManager { get; set; }
     
            /// <summary>
            /// Obsolete. Use LayoutTemplatePath instead.
            /// </summary>
            protected override string LayoutTemplateName => string.Empty;
     
            /// <summary>
            /// Gets the layout template's relative or virtual path.
            /// </summary>
            public override string LayoutTemplatePath
            {
                get { return string.IsNullOrEmpty(base.LayoutTemplatePath) ? layoutTemplatePath : base.LayoutTemplatePath; }
                set { base.LayoutTemplatePath = value; }
            }
     
            protected virtual Label LblKeydatesMessage => Container.GetControl<Label>("lblKeydatesMessage", true);
            protected virtual DropDownList DdlSubject => Container.GetControl<DropDownList>("ddlSubject", true);
            protected virtual ListView RptKeyDatesNews => Container.GetControl<ListView>("rptKeyDatesNews", true);
            protected virtual Label LblTrendingMessage => Container.GetControl<Label>("lblTrendingMessage", true);
            protected virtual ListView RptTrendingTopics => Container.GetControl<ListView>("rptTrendingTopics", true);
            protected virtual ListView PostListView => Container.GetControl<ListView>("PostListView", true);
            protected virtual HiddenField PageNumberHiddenField => Container.GetControl<HiddenField>("pageNumberHiddenField", true);
            protected virtual TextBox TxtSearch => Container.GetControl<TextBox>("txtSearch", true);
            protected virtual TextBox TxtMonthPicker => Container.GetControl<TextBox>("txtMonthPicker", true);
            protected virtual DropDownList DdlByPost => Container.GetControl<DropDownList>("ddlByPost", true);
            protected virtual Panel PnlShowDiscussion => Container.GetControl<Panel>("pnlShowDiscussion", true);
            protected virtual Panel PnlDoNotShowDiscussion => Container.GetControl<Panel>("pnlDoNotShowDiscussion", true);
            protected virtual ImageButton ImgBtnSharepoint => Container.GetControl<ImageButton>("ImgBtnSharepoint", true);
            protected virtual ListView ReplyListView => Container.GetControl<ListView>("replyListView", true);
            protected virtual Label LblGroupName => Container.GetControl<Label>("lblGroupName", true);
            protected virtual HiddenField HdfSharePointLink => Container.GetControl<HiddenField>("hdfSharePointLink", true);
            protected virtual Button NextButton => Container.GetControl<Button>("NextButton", true);
            protected virtual Button BtnCreateTopic => Container.GetControl<Button>("btnCreateTopic", true);
            protected virtual Button BtnFilter => Container.GetControl<Button>("btnFilter", true);
            protected virtual Button BtnSearch => Container.GetControl<Button>("btnSearch", true);
            protected virtual HiddenField HdnGroupId => Container.GetControl<HiddenField>("hdnGroupId", true);
     
            /// <summary>
            /// Initializes the controls.
            /// </summary>
            /// <param name="container"></param>
            /// <remarks>
            /// Initialize your controls in this method. Do not override CreateChildControls method.
            /// </remarks>
            protected override void InitializeControls(GenericContainer container)
            {
                ScriptManager = ScriptManager.GetCurrent( Page );
                LblGroupName.Text = "UNKNOWN";
                PnlDoNotShowDiscussion.Visible = true;
                HdnGroupId.Value = "{" + GroupId + "}"; // GroupId value is 00000000-0000-0000-0000-000000000000 as shown on the client
                // Code cut for brevity
                if (Page.IsPostBack || GroupId == Guid.Empty || GroupId == default(Guid)) return; // We get here and no further
                PnlShowDiscussion.Visible = true;
                PnlDoNotShowDiscussion.Visible = false;
            }
            public static readonly string layoutTemplatePath = "~/CustomControls/GroupDiscussion/GroupDiscussion.ascx";
        }
    }

    Control markup

    <%@ Control Language="C#"%>
    <div class="thanks-content discussion-content">
        <asp:Panel runat="server" ID="pnlShowDiscussion" Visible="false">
            <div class="SignPainter-HouseScript">
                Welcome to the
                <asp:Label ID="lblGroupName" runat="server"></asp:Label>
                group!
            </div>
        </asp:Panel>
        <asp:Panel runat="server" ID="pnlDoNotShowDiscussion" Visible="false">
            <asp:HiddenField runat="server" ID="hdnGroupId" value=""/>
            <!-- This what we are seeing -->
            Group not selected or no longer valid.
        </asp:Panel>
    </div>

     

1 posts, 0 answered