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

Forums / Developing with Sitefinity / User Control with Sitefinity Image controls does not work

User Control with Sitefinity Image controls does not work

2 posts, 0 answered
  1. Paritosh Arya
    Paritosh Arya avatar
    10 posts
    Registered:
    18 Dec 2009
    03 Sep 2010
    Link to this post
    I developed few user controls and they work fine if they are part of the Sitefinity project(website), but it will be tedious work to upload controls one by one from the Admin interface when deployed in production environment. So I created new Web application project for all my user controls, it compiles and I can even add dll for my controls to the toolbox and all the controls start showing up on the toolbox; but when I add the control (custom control containing sitefinity controls  - like sitefinity image control), it throws exception.

    [NullReferenceException: Object reference not set to an instance of an object.]
       SS.User.Controls.ImageDataControl.get_ImageUrl() +59
      
    [TargetInvocationException: Property accessor 'ImageUrl' on object 'SS.User.Controls.ImageDataControl' threw the following exception:'Object reference not set to an instance of an object.']
       System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +390
       Telerik.Cms.Data.WebControlBase.SaveControlState(Control control, Control defCtrl, PropertyDescriptorCollection properties) +864
       Telerik.Cms.Data.WebControlBase.SaveControlState(Control control) +320
       Telerik.Cms.Data.WebControlBase.VerifyObject() +57
       Nolics.ORMapper.Base.OdbClassHelper.VerifyClass(IOdbClass cl) +58
       Telerik.Cms.Data.WebControlBase.Nolics.ORMapper.Base.IOdbClass.BeginCommit() +28
       Nolics.ORMapper.Base.Transaction.Commit(Boolean fCleanIfSuccess) +1419
       Nolics.ORMapper.Base.Transaction.Commit() +34
       Telerik.Cms.Data.StagedPage.AddControl(String containerId, ICmsWebControl cmsControl, Int32 ordinal) +586
       Telerik.Cms.Data.StagedPage.AddControl(String containerId, Type type, Int32 ordinal, String controlId) +244
       Telerik.Cms.Web.UI.ToolBar.AddContol(String controlName, String zoneId, Int32 ordinal) +601
       Telerik.Cms.Web.UI.Toolbox.Button_Command(Object sender, CommandEventArgs e) +412
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +108
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Here's .ascx and .cs code -
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImageDataControl.ascx.cs" Inherits="SS.User.Controls.ImageDataControl" %>
      
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <%@ Register Assembly="SS.Custom.Controls" Namespace="SS.Custom.Controls" TagPrefix="ss" %>
    <div class="imageData">
        <div id="idImageDiv" runat="server" class="imageControl">
            <sfWeb:SitefinityImage ID="siImage" runat="server"/>
        </div>
        <div id="idHeadlineDiv" runat="server" class="headlineControl">
            <ss:Headline id="headLine" runat="server"/>
        </div>
        <div id="idBulletedListDiv" runat="server" class="bulletedListControl">
            <ss:BulletedList id="bulletedList" runat="server"/>
        </div>
    </div>


    namespace SS.User.Controls
    {
        public partial class ImageDataControl : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
      
            }
      
      
            #region Image
      
            [WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Cms.Engine")]
            [TypeConverter(typeof(StringConverter))]
            [Category("Image")]
            public string ImageUrl
            {
                get
                {
                    return siImage.ImageUrl;
                }
                set
                {
                    siImage.ImageUrl = value;
                }
            }
      
            [TypeConverter(typeof(BooleanConverter))]
            [Category("Image")]
            public bool ShowImage
            {
                get
                {
                    return siImage.Visible;
                }
                set
                {
                    if (value)
                    {
                        idImageDiv.Style.Add("display", "block");
                    }
                    else
                    {
                        idImageDiv.Style.Add("display", "none");
                    }
                    siImage.Visible = value;
                }
            }
      
            #endregion
      
            #region Headline
      
            [Category("Headline")]
            public string Header
            {
                get
                {
                    return headLine.Header;
                }
      
                set
                {
                    headLine.Header = value;
                }
            }
      
            private List<string> _headlineItems;
            [Category("Headline")]
            [WebEditor("SS.Custom.Controls.SaxonBulletedListEditor, SS.Custom.Controls"), Browsable(true)]
            [TypeConverter("SS.Custom.Controls.ListConverter, SS.Custom.Controls")]
            public List<string> HeadlineList
            {
                get
                {
                    if (headLine.HeadlineList == null)
                        headLine.HeadlineList = new List<string>();
                    return headLine.HeadlineList;
                }
                set
                {
                    headLine.HeadlineList = value;
                }
            }
      
            [TypeConverter(typeof(BooleanConverter))]
            [Category("Headline")]
            public bool ShowHeadline
            {
                get
                {
                    return headLine.Visible;
                }
                set
                {
                    if (value)
                    {
                        idHeadlineDiv.Style.Add("display", "block");
                    }
                    else
                    {
                        idHeadlineDiv.Style.Add("display", "none");
                    }
                    headLine.Visible = value;
      
                }
            }
      
            #endregion
      
            #region BulletedList
      
            [Category("Bulleted List")]
            public string HeaderText
            {
                get
                {
                    return bulletedList.HeaderText;
                }
      
                set
                {
                    bulletedList.HeaderText = value;
                }
            }
      
            [Category("Bulleted List")]
            [WebEditor("SS.Custom.Controls.SaxonBulletedListEditor, SS.Custom.Controls"), Browsable(true)]
            [TypeConverter("SS.Custom.Controls.ListConverter, SS.Custom.Controls")]
            public List<string> ListItems
            {
                get
                {
                    if (bulletedList.ListItems == null)
                        bulletedList.ListItems = new List<string>();
                    return bulletedList.ListItems;
                }
                set
                {
                    bulletedList.ListItems = value;
                }
            }
      
            [TypeConverter(typeof(BooleanConverter))]
            [Category("Bulleted List")]
            public bool ShowBulletedList
            {
                get
                {
                    return bulletedList.Visible;
                }
                set
                {
                    if (value)
                    {
                        idBulletedListDiv.Style.Add("display", "block");
                    }
                    else
                    {
                        idBulletedListDiv.Style.Add("display", "none");
                    }
                    bulletedList.Visible = value;
                }
            }
      
            #endregion
        }
    }


    When I debug the code, siImage (SitefinityImage) is always null and hence throws exception. But when I use the same control as part of Sitefinty project (create folder for user controls in website and keep controls there), the same code works. Could you please help me out if I am missing something.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    06 Sep 2010
    Link to this post
    Hello Paritosh Arya,

    Your controls should be compiled into a code library project not in web application project. Then add the compiled dll into the bin folder and you will be able to use your custom controls. Try compiling them in code library project.

    Regards,
    Radoslav Georgiev
    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
2 posts, 0 answered