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

Forums / Developing with Sitefinity / Custom control interfering with edit page postback

Custom control interfering with edit page postback

4 posts, 1 answered
  1. Duncan Evans
    Duncan Evans avatar
    122 posts
    Registered:
    07 Jul 2009
    04 Dec 2009
    Link to this post
    Morning,

    I have borrowed a marketplace control and have made some modifications to it. Here is the original (http://www.sitefinity.com/marketplace/modules/ad-banner-control.aspx). But i need some help as the control seems to be interfering with the page edits postback. For example, if i am editing a page and the control is on the page, if i then hit save or any other function, nothign happens because the rendering of the control seems to stop the postback of the edit page.

    Now i thought that by adding "if (!Page.IsPostBack)" this would NOT render execute the method that renders the control on postback. But on the edit page, IsPostBack comes back false every time.

    The modification i have made are extensive.
    1) It is not in C#
    2) Instead of building a ImageButon control in the code behind and adding the dynamic control to a pnl, i simple have the control int he ASCX file.
    3) I have added additional functions such as using a ImageButton instead of Image as i want it to link out
    4) I also use IGenericContent so that i can place generic content if i choose

    Could someone take a look at this and help me figure out a way to make it so that it does not run or mess with other page functions, especially when editing a page in Sitefinity.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AdRotator.ascx.cs" Inherits="UserControls_AdRotator" %> 
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %> 
     
    <div id="advertising"
        <sfweb:genericcontent runat="server" id="GenericContent1" /> 
        <asp:ImageButton ID="imgAd" runat="server" /> 
    </div> 
     

    using System; 
    using System.Collections; 
    using System.ComponentModel; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Cms.Engine; 
    using Telerik.Cms.Engine.WebControls; 
    using Telerik.Cms.Web.UI; 
    using Telerik.Framework.Web.Design; 
    using Telerik.Libraries; 
    using Telerik.Web; 
     
    [ControlDesignerAttribute("Telerik.Cms.Engine.WebControls.Design.GenericContentDesigner, Telerik.Cms.Engine")] 
    partial class UserControls_AdRotator : System.Web.UI.UserControl, IGenericContent 
        #region Fields 
     
        private Guid[] _libID; 
        private string _libraryName = string.Empty; 
        private string _PostToUrl = string.Empty; 
        #endregion 
        #region Properties 
     
        [TypeConverter("Telerik.Framework.Utilities.GuidArrayConverter, Telerik.Framework")] 
        [Category("Settings"), WebEditor("Telerik.Libraries.WebControls.CustomLibrarySelector, App_Code")] 
        public Guid[] LibraryGuids 
        { 
            get 
            { 
                return _libID; 
            } 
            set 
            { 
                _libID = value; 
            } 
        } 
     
        [Category("Settings"), Description("")] 
        public virtual string PostToUrl 
        { 
            get 
            { 
                return _PostToUrl; 
            } 
            set 
            { 
                _PostToUrl = value; 
            } 
        } 
        #endregion 
        #region Protected Methods 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                BuildAdItem(); 
            } 
        } 
        #endregion 
        #region Private Methods 
     
        private void BuildAdItem() 
        { 
            IList LibraryItems = null
     
            foreach (Guid LibraryGuid in LibraryGuids) 
            { 
                ILibrary Library = new LibraryManager().GetLibrary(LibraryGuid); 
                LibraryItems = Library.GetItems(); 
            } 
     
            Random rndGen = new Random(DateTime.Now.Second); 
            IContent indImage = LibraryItems[rndGen.Next(0, LibraryItems.Count)] as IContent; 
     
            imgAd.ImageUrl = string.Format("{0}.sflb.ashx", indImage.Url); 
            imgAd.PostBackUrl = PostToUrl; 
        } 
        #endregion 
        #region IGenericContent Members 
        [CmsBrowsable(false)] 
        [CmsPersistable(true)] 
        public string Content 
        { 
            get 
            { 
                return GenericContent1.Content; 
            } 
            set 
            { 
                GenericContent1.Content = value; 
            } 
        } 
        [Browsable(false)] 
        public Guid ContentID 
        { 
            get 
            { 
                return GenericContent1.ContentID; 
            } 
            set 
            { 
                GenericContent1.ContentID = value; 
            } 
        } 
        public string ProviderName 
        { 
            get 
            { 
                return GenericContent1.ProviderName; 
            } 
            set 
            { 
                GenericContent1.ProviderName = value; 
            } 
        } 
        [Browsable(false)] 
        public IContent SharedContent 
        { 
            get 
            { 
                return this.GenericContent1.SharedContent; 
            } 
        } 
        public bool UseStagedVersion 
        { 
            get 
            { 
                return GenericContent1.UseStagedVersion; 
            } 
            set 
            { 
                GenericContent1.UseStagedVersion = value; 
            } 
        } 
        [CmsBrowsable(false), CmsPersistable(true)] 
        public bool HasDynamicLinks 
        { 
            get 
            { 
                return GenericContent1.HasDynamicLinks; 
            } 
            set 
            { 
                GenericContent1.HasDynamicLinks = value; 
            } 
        } 
        public string GetItemUrl(string provider, Guid id, bool resolveAsAbsoluteUrl) 
        { 
            return GenericContent1.GetItemUrl(provider, id, resolveAsAbsoluteUrl); 
        } 
        public void RenderBinaryContent(HtmlTextWriter writer) 
        { 
            GenericContent1.RenderBinaryContent(writer); 
        } 
        public void RenderTextContent(HtmlTextWriter writer) 
        { 
            GenericContent1.RenderTextContent(writer); 
        } 
        #endregion 
     

    Any help would be great.

    Thanks,

    Duncan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Dec 2009
    Link to this post
    Hi Duncan Evans,

    The problem most probably comes from the reason that you are trying to wrap GenericContent control in a user control. You have to convert the code to a custom control which is pretty easy.

    I suggest that you should review the following posts

    values-not-saving-in-uploaded-usercontrol
    How to wrap a Generic Content control in 3.6 SP1 How to wrap a Generic Content control in 3.6 SP1

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Duncan Evans
    Duncan Evans avatar
    122 posts
    Registered:
    07 Jul 2009
    04 Dec 2009
    Link to this post
    You are correct, thought i would be able to get away with that. For the sake of ease, i will just seperate the controls (remove the generic content control)..

    Thanks for the heads up.

    Duncan
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Dec 2009
    Link to this post
    Hello Duncan Evans,

    Thanks for getting back to me. You can mark the post as "answer" so it could help to the other Community members if they have same/similar problem.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 1 answered