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

Forums / Developing with Sitefinity / Hide content of GenericContent control while editing template/page

Hide content of GenericContent control while editing template/page

6 posts, 0 answered
  1. ckalan
    ckalan avatar
    3 posts
    Registered:
    04 Sep 2006
    22 Aug 2010
    Link to this post
    Hi, I am new to Sitefinity and in my first trials, i tried to create a template. Uploaded my masterpage with one ContentPlaceHolder in it. Then added a GenericContent control to this placeholder.

    Then i put my html codes by editing this GenericContent. However, because of a javascript ( or css , i am not sure ) problem, i can see my html in the box, but can not see the "Edit" link of the GenericContent part while editing my template. Probably something overlaps with these tool buttons.

    The problem is , i can no longer edit this content because of my not seeing the "Edit" button. The solution i found is to use firebug and hide some of my content by deleting the elements. Then i can see the button there.

    So, what i wonder is, can i create a component similar to GenericContent which does not display any content when in Edit mode for potential future problems like this. I just want to add my html content to this part but it is not important for me to see the content in the page while i am editing the page / template.

    I tried to create a control GenericContent2 which inherits from GenericContent and i first tried to remove all render part in it to see if it is really used. When i put this control to some part of my page, and edit it and put my html in it, then nothing changes and the content is displayed as i entered. So i guess, my pages do not use this control. I can't understand why.. The code of the control is as follows


    public class GenericContent2:GenericContent
    {
        public GenericContent2()
        {
           
            throw new Exception("abcd");
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            throw new Exception("abcd");
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            //base.Render(writer);
        }
    }


    What should i do to create a control for this task ? Or do i have any chance to edit a content part without using template editing feature ( except going to the database and changing the content by using sql of course ) ?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Aug 2010
    Link to this post
    Hi ckalan,


    Then i put my html codes by editing this GenericContent. However, because of a javascript ( or css , i am not sure ) problem, i can see my html in the box, but can not see the "Edit" link of the GenericContent part while editing my template. Probably something overlaps with these tool buttons.

    Switch the page edit mode to "Classic" in case you are using "Overlay" and try to edit the control. For the ContentPlaceHolder controls defined in your master page use short closing tag. The issue appears when there are spaces between opening and closing tags of a divs and between opening and closing tags of ContentPlaceHolder control.

    So, what i wonder is, can i create a component similar to GenericContent which does not display any content when in Edit mode for potential future problems like this.

    You can check the current page mode and hide the control or its content

    if( HttpContext.Current.Request.QueryString[ "cmspagemode" ] == "edit" )
      {
       // hide the content or your control
      }


    Kind regards,
    Ivan Dimitrov
    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
  3. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    23 Aug 2010
    Link to this post
    Hi ckalan,

    You don't need to create a new Generic content control for this purpose. You can simply workaround the problem while in edit mode. After using firebug, was it a CSS or a JS issue?

    You can simply check the URL and see if the page is in edit mode using javascript (Querystring: cmspagemode=edit)
    and you can disable the code with an if statement checking the page mode on page load.

    Cheers,

    George
  4. ckalan
    ckalan avatar
    3 posts
    Registered:
    04 Sep 2006
    23 Aug 2010
    Link to this post
    Thanks for your response. Actually I have already read about everything in the documentation and blogs about the problem and tried those things.

    The problem is, i think when you are editing a template, "GenericContent2" is not run. To see this, i created the control i sent in my previous message and put it into the App_Code folder and added it to the toolbox in the web.config.

    I see my control in the toolbox as "GenericContent2" and i chose it and put it to a place where there is a ContentPlaceHolder section.

    But as you see in my code, there are exceptions thrown and nothing in the render method. But even if this is the case, i can see the content in the page. So i think i should use another control to do what i want. I have no idea about where to start for this because i don't know which control is rendered in the templateeditor to show the generic content.
  5. ckalan
    ckalan avatar
    3 posts
    Registered:
    04 Sep 2006
    23 Aug 2010
    Link to this post
    And btw, the reason why i can't see the edit button came up to be a css problem so preventing javascript code from running does not help.

    I think, Sitefinity has to think about editing a content section through somewhere else ( in addition to these classic and overlay views)  so that even if there is a problem like this, the user can go to some page, find a genericcontent section by searching a meta field value and then open it and edit the content.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Oct 2010
    Link to this post
    Hi ckalan,

    Your code throws an explicit exception directly in the custom class constructor. You are doing this explicitly and the constructor of the control is called before CreateChildControls and Render method. You can check the page mode by suing the provided code before you throw the exception.

    The page edit mode relies on a js and Microsoft Ajax libraries. Any custom code that you add there ( css, js  etc) could break the layout and destroy the place holder areas. In this cases you can perform rollback or restore from History section of this page or fix the issues in your stylesheet or js code.

    Regards,
    Ivan Dimitrov
    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
Register for webinar
6 posts, 0 answered