inheriting from GenericContentView
Please get me started on how to do this.
Here is what I have tried so far. I:
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.
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"
;
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
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
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
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
>
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.
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