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

Forums / Developing with Sitefinity / Extending the Generic Content Editor

Extending the Generic Content Editor

10 posts, 0 answered
  1. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    14 Jan 2011
    Link to this post
    Hi Support,

    I am looking to extend the functionality of the generic content editor namely a couple of extra properties.

    I have read the article http://www.sitefinity.com/devnet/kb/sitefinity-3-x/how-to-wrap-a-generic-content-control-in-3-6-sp1.aspx. I decided to downlad the sample provided and as I am working in VB I converted it from c#.

    Anyway I have read the article over and over and I cannot figure out why I am getting the following error: Property accessor 'ContentTitle' on object 'ExtendGenericContentEditor.GCWrapper' threw the following exception:'Invalid resource name (ExtendGenericContentEditor.Resources.Templates.GC_WrapperTemplate.ascx) for assembly (ExtendGenericContentEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) or empty template.'

    I have made very minor modifications i.e. the namespace and assembly name I have also changed the following
    1.#Region "constants"
    2.        'Public Const GCWrapperLayoutTemplatePath As String = "DidoTestControls.Resources.Templates.GC_WrapperTemplate.ascx"
    3.        Public Const GCWrapperLayoutTemplatePath As String = "ExtendGenericContentEditor.Resources.Templates.GC_WrapperTemplate.ascx"
    4.#End Region
    To reflect the namespace change.

    The template is set to an embedded resource under build type. I cannot see why the error is being produced.

    Thanks in advance

    Dan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Jan 2011
    Link to this post
    Hi Daniel,

    1. The path to the template is not correct.

    2. The template is not built as an embedded resources.

    Best wishes,
    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. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    14 Jan 2011
    Link to this post
    Hi Ivan,

    The template is built as an embedded resource this is under the build type correct?

    Below is the code:
    001.Imports System.ComponentModel
    002.Imports System.Web.UI
    003.Imports Telerik.Cms.Web.UI
    004.Imports Telerik.Web
    005.Imports Telerik.Cms.Engine.WebControls
    006.Imports Telerik.Framework.Web
    007.Imports System.IO
    008.Imports System.Reflection
    009. 
    010.Namespace ExtendGenericContentEditor
    011.    ''' <summary>
    012.    ''' Demonstrates how to wrap a Generic Content control and use the full functionality
    013.    ''' of the base class.
    014.    ''' </summary>
    015.    <DefaultProperty("ContentTitle")> _
    016.    <ToolboxItem(GetType(GCWrapperToolboxItem))> _
    017.    <ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")> _
    018.    Public Class GCWrapper
    019.        Inherits GenericContent
    020.#Region "layout properties"
    021. 
    022.        ''' <summary>
    023.        ''' Used for loading controls from a template (defines the layout)
    024.        ''' </summary>
    025.        <Browsable(False)> _
    026.        Protected Overridable ReadOnly Property Container() As GenericContainer
    027.            Get
    028.                If Me.m_container Is Nothing Then
    029.                    Me.m_container = New GenericContainer()
    030.                    If Me.LayoutTemplate IsNot Nothing Then
    031.                        Me.LayoutTemplate.InstantiateIn(Me.m_container)
    032.                    End If
    033.                End If
    034.                Return Me.m_container
    035.            End Get
    036.        End Property
    037. 
    038.        ''' <summary>
    039.        ''' Gets or sets the template defining the layout of the control.
    040.        ''' </summary>
    041.        <TemplateContainer(GetType(GenericContainer))> _
    042.        <PersistenceMode(PersistenceMode.InnerProperty)> _
    043.        <Description("Gets or sets the template defining the layout of the control.")> _
    044.        <Browsable(False)> _
    045.        <DefaultValue(GetType(ITemplate), "")> _
    046.        Public Overridable Property LayoutTemplate() As ITemplate
    047.            Get
    048.                If Me.m_layoutTemplate Is Nothing Then
    049.                    Me.m_layoutTemplate = ControlUtils.GetTemplate(Me.LayoutTemplatePath, Me.LayoutTemplateName, Me.[GetType]())
    050.                End If
    051.                Return Me.m_layoutTemplate
    052.            End Get
    053.            Set(ByVal value As ITemplate)
    054.                Me.m_layoutTemplate = value
    055.            End Set
    056.        End Property
    057. 
    058. 
    059.        ''' <summary>
    060.        ''' Gets or sets the path to a custom layout template for the control.
    061.        ''' </summary>
    062.        <Browsable(True)> _
    063.        <Category("Appearance")> _
    064.        <Description("Gets or sets the path to a custom layout template for the control.")> _
    065.        <EmbeddedTemplate(GCWrapper.GCWrapperLayoutTemplatePath, "Layout template path for GC wrapper", "/Templates/", True, "2009/3/31")> _
    066.        Public Overridable Property LayoutTemplatePath() As String
    067.            Get
    068.                Dim persistedValue As Object = Me.ViewState("LayoutTemplatePath")
    069. 
    070.                If persistedValue IsNot Nothing Then
    071.                    Return DirectCast(persistedValue, String)
    072.                Else
    073.                    Return [String].Empty
    074.                End If
    075.            End Get
    076.            Set(ByVal value As String)
    077.                Me.ViewState("LayoutTemplatePath") = value
    078.            End Set
    079.        End Property
    080. 
    081.        ''' <summary>
    082.        ''' Gets the name of the embedded layout template. This property must be overridden to provide the path (key) to an embedded resource file.
    083.        ''' </summary>
    084.        <Browsable(False)> _
    085.        Public Overridable ReadOnly Property LayoutTemplateName() As String
    086.            Get
    087.                Return GCWrapper.GCWrapperLayoutTemplatePath
    088.            End Get
    089.        End Property
    090. 
    091.#End Region
    092. 
    093.#Region "properties"
    094. 
    095.        ''' <summary>
    096.        ''' The text of the title above the content area
    097.        ''' </summary>
    098.        <Browsable(True)> _
    099.        <Category("Appearance")> _
    100.        <Description("The text of the title above the content area")> _
    101.        <TypeConverter(GetType(StringConverter))> _
    102.        Public Property ContentTitle() As String
    103.            Get
    104.                Return Me.ContentTitleText.Text
    105.            End Get
    106.            Set(ByVal value As String)
    107.                Me.ContentTitleText.Text = value
    108.            End Set
    109.        End Property
    110. 
    111.#End Region
    112. 
    113.#Region "control references"
    114. 
    115.        ''' <summary>
    116.        ''' The title above the content
    117.        ''' </summary>
    118.        <Browsable(False)> _
    119.        Public ReadOnly Property ContentTitleText() As ITextControl
    120.            Get
    121.                Return Me.Container.GetControl(Of ITextControl)("title", True)
    122.            End Get
    123.        End Property
    124. 
    125.        ''' <summary>
    126.        ''' The wrapped generic content control
    127.        ''' </summary>
    128.        <Browsable(False)> _
    129.        Public ReadOnly Property ContentPlaceholder() As ITextControl
    130.            Get
    131.                Return Me.Container.GetControl(Of ITextControl)("content", True)
    132.            End Get
    133.        End Property
    134. 
    135.#End Region
    136. 
    137.#Region "methods"
    138. 
    139.        ''' <summary>
    140.        ''' This message will be displaye when the control is initially dragged
    141.        ''' onto the design surface
    142.        ''' </summary>
    143.        ''' <returns>a message to display when there is no content in the control</returns>
    144.        Public Overrides Function SetEmptyControlDefaultMessage() As String
    145.            Return "This control will not display properly in design mode!"
    146.        End Function
    147. 
    148.        ''' <summary>
    149.        ''' Called to write the actual html for this control
    150.        ''' </summary>
    151.        ''' <remarks>
    152.        ''' Will not render properly in design mode due to the implementation of the
    153.        ''' GenericContentDesigner.
    154.        ''' </remarks>
    155.        ''' <param name="writer">a stream that is specialized in wrtinig html output</param>
    156.        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
    157.            Dim content As StringWriter = Nothing
    158.            Dim contentWriter As HtmlTextWriter = Nothing
    159. 
    160.            Try
    161.                ' if in normal mode, output the full content of the control
    162.                If Not Me.DesignMode Then
    163.                    ' first, we need to "extract"
    164.                    content = New StringWriter()
    165.                    contentWriter = New HtmlTextWriter(content)
    166.                    MyBase.Render(contentWriter)
    167. 
    168.                    Me.ContentPlaceholder.Text = content.ToString()
    169. 
    170.                    ' we need to do this manually, as generic content control renders its
    171.                    ' content directly and does not inherit CompositeControl,
    172.                    ' so it will not render out template correctly (not at all, actually)
    173.                    For Each child As Control In Me.Controls
    174.                        child.RenderControl(writer)
    175.                    Next
    176.                    ' for some reason, CreateChildConrols is never called, so we do this manually
    177.                    If Not Me.Controls.Contains(Me.Container) Then
    178.                        Me.Container.RenderControl(writer)
    179.                    End If
    180.                Else
    181.                    ' if in edit (design) mode, output the content of the genreric content control
    182.                    ' THIS IS REQUIRED
    183.                    MyBase.Render(writer)
    184.                End If
    185.            Finally
    186.                ' I don't use "using", as I dislike nested "using"-s
    187.                If content IsNot Nothing Then
    188.                    content.Dispose()
    189.                End If
    190.                If contentWriter IsNot Nothing Then
    191.                    contentWriter.Dispose()
    192.                End If
    193.            End Try
    194.        End Sub
    195. 
    196.#End Region
    197. 
    198.#Region "constants"
    199.        'Public Const GCWrapperLayoutTemplatePath As String = "DidoTestControls.Resources.Templates.GC_WrapperTemplate.ascx"
    200.        Public Const GCWrapperLayoutTemplatePath As String = "ExtendGenericContentEditor.Resources.Templates.GC_WrapperTemplate.ascx"
    201.#End Region
    202. 
    203.#Region "fields"
    204. 
    205.        ''' <summary>
    206.        ''' Holds the value of the LayoutTemplate property
    207.        ''' </summary>
    208.        Private m_layoutTemplate As ITemplate
    209. 
    210.        ''' <summary>
    211.        ''' Holds the value of the Container property
    212.        ''' </summary>
    213.        Private m_container As GenericContainer
    214. 
    215.#End Region
    216. 
    217.    End Class

    The Template is located in the 'Resource\Templates' Folder and is called GC_WrapperTemplate.ascx.

    Please can you advise on what the correct path should be?

    Thanks

    Dan
  4. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    17 Jan 2011
    Link to this post
    Hi Guys,

    Just wondering what the status is on this - dont mean to be pushy just really eager to get going with this.

    Thanks again for looking into it.

    Dan
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hi Daniel,

    You can see the build action when you right click on the file and select "Properties" . The build action should be  "Embedded Resource". The error you are getting is thrown, because the path to the template you use is not correct or its build action is not Embedded Resource

    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
  6. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    18 Jan 2011
    Link to this post
    Hi Ivan,

    Im sorry but i seem to be missing something here.

    I have tried to use the original files and I am still having trouble adding the control to a page.

    Do I need to place the GC_WrapperTemplate.ascx File on the website somewhere?

    Thanks for your patience with me - I apologise!

    Dan
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Jan 2011
    Link to this post
    Hello Daniel,

    GC_WrapperTemplate.ascx should be added as an embedded resource inside the class library where you crate your custom control.

    Best wishes,
    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
  8. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    19 Jan 2011
    Link to this post
    Hi Ivan,

    It is an embedded resource. Im not sure way I cannot map to it correctly.

    Thanks

    Daniel
  9. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    19 Jan 2011
    Link to this post
    Sorry Used the wrong control - silly me!

    I am still experiencing this issue.

    Any other advice would be gratefully appreciated.

    Thanks

    Dan
  10. Daniel
    Daniel avatar
    62 posts
    Registered:
    20 Apr 2009
    19 Jan 2011
    Link to this post
    Hi Ivan,

    I have managed to sort the issue.

    In vb.net the path only needs to be :Namespace.Filename.extension

    Whereas c# needs the folders etc.

    Thanks for all your help.

    Dan
Register for webinar
10 posts, 0 answered