inheriting from GenericContentView

Posted by Community Admin on 03-Aug-2018 20:47

inheriting from GenericContentView

All Replies

Posted by Community Admin on 17-Dec-2010 00:00

  • I want to create a widget which is a modified, SiteFinity Content block (this is the name that appears in the "Drag widgets" list of the Edit-A-Page screen).  I believe this is the same control that is referenced in the ToolboxesConfig.Config file as  Telerik.Sitefinity.Modules.GenericContent.Web.UI.GenericContentView.

 

Please get me started on how to do this.

 

Here is what I have tried so far. I:

  • created a new .ascx file
  • added this to the CodeBehind file
    • using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
  • this, and other usings, are already in the CodeBehind file
    • using System.Web.UI;
    • using System.Web.UI.WebControls;

 

  • in the Page_Load event for the .ascx file I put this:

GenericContentView gcv = new GenericContentView();

this.Controls.Add(gcv);

 

When I open a page in the browser that has this User Control in it I get this error:

[NullReferenceException: Object reference not set to an instance of an object.]

System.Web.UI.ControlExtensions.GetUrlParameters(Control control) +135

 

Please get me started on how to make a widget that is a modified version of the "Content block" widget.  Thanks.

Posted by Community Admin on 21-Dec-2010 00:00

Hello Phil,

You should use ContentBlock class instead of GenericContentView. To create a custom control that changes the logic of ContentBlock you need to create a custom class that inherits from it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.Web.UI.Fields;
 
namespace Telerik.Sitefinity.Samples
    [ControlDesigner(typeof(ContentBlockDesignerCustom))]
    class ContentBlockCustom : ContentBlock
    
 
 
        protected override string LayoutTemplateName
        
            get
            
                return ContentBlockCustom.layoutTemplateName;
            
        
 
 
         
 
        private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.ContentBlock.ascx";
 
    
 
 

If you just want to add the control dynamically, please use ContentBlock class

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

Posted by Community Admin on 21-Dec-2010 00:00

Thanks Ivan for your reply.

My build of SF does not like private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.ContentBlock.ascx";

I get this error in the web page where I am trying to use the new control:   Invalid resource name "Telerik.Sitefinity.Samples.Resources.ContentBlock.ascx" for assembly "App_Code.21feahd0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" or empty template.

When we look in the directories that that namespace, or path, or whatever it is, indicates, we do not see either that path or that file.  We are using SF 4.0 build 4.0.992.0.  That path is not in our SDK either.

Where can we find that file?

Thanks

Posted by Community Admin on 21-Dec-2010 00:00

Hi Phil,

1. You need to use a custom class library, not App_Code folder
2. The control template should be an embedded resource.

If you use App_Code the template path has to be returned directly in the property as a relative path.

All the best,
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

Posted by Community Admin on 21-Dec-2010 00:00

Thanks again Ivan.

I am pretty sure that I understand what you are saying and we'll adjust. 

But when you say "as a relative path",  that is the problem I still have:  We cant find that file (But when you say "as a relative path",  that is the problem I still have:  We cant find that file (ContentBlock.ascx).  So that issue is stopping us whether we use an App_Code approach or the class library approach.

Can you tell me how to find that file?

Thanks

Posted by Community Admin on 21-Dec-2010 00:00

Hello Phil,

Here is the makup of the template

<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<asp:Literal ID="contentHtml" runat="server"></asp:Literal>


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

Posted by Community Admin on 21-Dec-2010 00:00

Thanks Ivan.  We are making progress.

We made a class that inherits from ContentBlock and wired that up to an .ascx file that we created with the markup you gave me.  We registered the new control in SF using the gui, and it appears in our widgets toolbox in the Edit-A-Page screen.  We can drag it onto the design surface but when we click Edit (so that we can enter our content) we get a control designer that does not include the big textarea for entering content that it should (see attached picture).

Possible cause: when we put the following in our new .ascx file
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
Visual Studio wont allow "BrowseAndEdit" at the end there.  We deleted that in order to build the solution. We are using SF 4.0 build 4.0.992.0.

The other thing I am wondering about is the following code which you gave us:
[ControlDesigner(
typeof(ContentBlockDesignerCustom))]
Since our issue is with the ControlDesigner, maybe that line needs tweaking(?)

Thanks again.

Posted by Community Admin on 21-Dec-2010 00:00

Hello Phil,

This is an attribute that is used when you want to have a control designer for your custom control. If the attribute is not there the built-in one should be loaded. Please take a look at How to create a widget tutorial which explains how to create custom controls.

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

This thread is closed