More in this section

Forums / Developing with Sitefinity / target/identify Generic Control

target/identify Generic Control

2 posts, 0 answered
  1. Johan Lausbcher
    Johan Lausbcher avatar
    10 posts
    08 Jul 2009
    15 Jul 2009
    Link to this post

    Is it possible to identify / or target the properties of a Generic Control in Sitefinity from a Javascript function inside a SiteMenu (or from any control/or MAster page for that matter) .

    What i'm trying to achieve is , is to be able to have a "Container" control(maybe Generic Control is not suited for this) within my Sitefinity page that can be Identified/targeted using 'getElementById' in my javascript in order to for example to change its url/ or the innerHtml, basically what you would normally be able to do when you target a div container in a page.
    I know doing it by targeting a div in your masterpage is possible , but i want to see if this is possible targeting a control within Sitefinity. more specifically if i have a current generic control with displaying static html , but at some point(client event) i want that html to be replaced with another . aspx page or different html.
    Or do simply target the div containerplaceholder where the generic control lies and replace it with whatever i want, but how do i call the same control back into that placeholder?

    Is it at possible to access such properties of a Sitefinity control provided the correct control is used in your SItefinity page.

    The bottomline then is to only have a section of your page with the "Container" control in your SItefinity page to change content(similar to what an iframe would achieve) when a menu item is clicked and not your whole page to be loaded with the new content you wwant to display.
    apologies if my question might have obvious solution , but i'm new to sitefinity , i'm trying to see what possiblities are there within sitefinity to certian things that i normally would do the conventional way not using sitefinity

    Any help/resource will be appreciated


    BlueAnt Productions

  2. Georgi
    Georgi avatar
    3583 posts
    28 Oct 2016
    17 Jul 2009
    Link to this post
    Hello Johan Lausbcher,

    The Generic Content control is a server side control. It is built in a such a way that in only renders the text/html set in the Content property. In other words, it will not render any other tag than the content. That said, you will not be able to find the control on the client side with a simple DOM search.
    I suggest you two approaches:

    1. Client side search:
    You can have the following structure:
    <div id="content1"
    //here goes the content control. Its Content value will be rendered here 

    Now you can perform a DOM search for the div tag, and everything inside will the text rendered by the control. The <contentplaceholder> tag will not be visible(rendered) on the public side.

    2. Server side search
    2.1. Finding control on the current page:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Cms.Web; 
    using Telerik.Cms; 
    using Telerik.Cms.Engine.WebControls; 
    public partial class UserControls_one : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
            CmsPageBase page = this.Page as CmsPageBase; 
            if (page != null
                CmsManager manager = new CmsManager(); 
                IPage mypage = manager.GetPage(page.CmsPage.ID); 
                foreach (ICmsWebControl control in mypage.Controls) 
                    if (control.TypeName.Equals(typeof(GenericContent).AssemblyQualifiedName)) 
                        GenericContent GCcontrol = (GenericContent)control.LoadControl(); 
                        string content = GCcontrol.Content; 

    2.2. Finding at changing a control:
       private void ReplacePhraseInGenericContentControls() 
            CmsManager manager = new CmsManager(); 
            // Get all GenericContent controls in a list  
            IList AllGenericCControls = manager.GetControls((typeof(Telerik.Cms.Engine.WebControls.GenericContent)).FullName, false); 
            // Change all content properties of these controls. The content property holds the non-shared generic content texts  
            foreach (ICmsWebControl control in AllGenericCControls) 
                Telerik.Cms.Engine.WebControls.GenericContent webControl = control.LoadControl(thisas Telerik.Cms.Engine.WebControls.GenericContent; 
                if (webControl != null
                    string stringContent = (string)webControl.Content; 
                        webControl.Content = "new content"

    I hope this helps.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered