Replacing Sitefinity UserControls with Regular UserControlsCancel

While reviewing the kb article on custom workflow notifications, I noticed that the main step was to make a code-behind file for the controltemplate usercontrol... this led me to wonder, why don't the controls have code-behind? Disabling them cripples a lot of functionality, and prevents us from adding custom code to do certain things simply, and as a result we have to do stuff like extend contentview controls...

Since the kb article basically suggests to turn this sitefinity control into a regular control, I tried just replacing it, deleting the sitefinity control and replacing it with a regular one, then copy-pasting all the html data, and adding custom code to its code behind. this was completely successful!

The "code-behind" for Sitefinity is almost entirely contained in DLL files. All of this is precompiled.

It would be possible to have separate code-behind files with raw source code for you to tweak. However, the upgrade path starts to get really messy in this scenario. We're already seeing this with the ControlTemplates. Your customizations will be overwritten with an upgrade and need to be re-applied.

Here is my personal opinion: I think Sitefinity already has too many files. A default installation of Sitefinity contains over 3,000 files. I would personally like to see this number reduced to under 20. I'm not joking.

One option for accomplishing this is to include ALL Sitefinity files in the Sitefinity DLLs. This means there would be very little you could alter in a default Sitefinity installation. However, I would like to include the option to export & use external ControlTemplates (and perhaps code-behind?) if you wish to customize parts of Sitefinity.

In this scenario your Sitefinity web site would consist of only a handful of Sitefinity DLL files. Everything else would be your customizations. Upgrading would simply involve uploading a handful of new Sitefinity DLL files. When you upgrade, it will be obvious where Sitefinity ends and your own customizations begin. None of it would be co-mingled.

What are your thoughts on this scenario?

So why is it that this model isn't encouraged? it's SOOOO much easier, and fits better within the asp.net programming model. I'm sure there's a good reason for this but I'd like to know what it is.

You have some golden advice included in your post. For any Sitefinity ControlTemplate you can configure a code-behind file and include some custom code. For example, I can include the following line at the beginning of my ~/Sitefinity/Admin/ControlTemplates/Events/ControlPanelInsert.ascx file:

This allows me to VERY EASILY attach custom code to existing Sitefinity controls. It's great! My only issue with this is the upgrade path. Ideally we keep "your stuff" separate from the "Sitefinity stuff". All of us are doing a poor job of that right now. I'm very interested in a ways to solve this without limiting your ability to customize Sitefinity.

For Type Editors, User Controls are unable to inherit from the WebUITypeEditor class.

For Control Designers, we need to cast the "base.DesignedControl" to make changes to the underlying properties.

Here is what this looks like:

1

(MyCustomClass) myClass = (MyCustomClass) base.DesignedControl;

2

myClass.myCustomProperty = "hello".

3

4

If we're dealing with only a User Control, how do we reference the UserControl's properties in a strongly typed way? There isn't a way (that I know of) to use the namespace to reference public properties stored in a User Control.

I could be wrong about all of this though. I'm anxious to learn from others if anyone has any tips.

i think a good idea would be to use the default control template and instantiate it via code instead of a user control. sitefinity can do this right? if the default control template file doesn't exist, it creates a default one that is just the basic of the basic (just the input controls) at run time.I don't know too much about the internals so I could be wrong...

this could be the default so that if users never use controltemplates and just use the builtin ones won't have to upgrade any user control files when a new release comes out.

while you're at it the default template could also dynamically render inputs for all the meta fields. you could define the control type (text, date, datetime, list, etc) and the default template would instantiate a corresponding field... that way meta fieds could be added with just one entry in web.config.

then if we want to use custom templates, we just create the markup for our control, including only the meta fields we need (everything else would be instantiated in the code behind dll compiled into sitefinity core) and code behind to handle events and additional processing.

this could be even FURTHER enhanced of these internal classes were exposed to us as partial classes, so that we could EXTEND them.

for example, if I want to handle the Save button click, I'd have to replace the control just as you did in your example, and make sure to manually wire up an event to the physical control that I had to place on the page. If, however, the button was a member of the internal class, you could just allow me in the partial class to add an event handler to the public property encapsulating that control:

public partial class ControlTemplateInsertControl

{

protected Page_Load(object sender, EventArgs e)

{

this.SaveButton.Click += new EventHandler(MyHandler);

}

}

of course I don't know TOO much about this stuff so I could be way off the mark...

My requirement is that i need to create a new modulle, which i have done taking help of developer manual.Know what i want is that give the business user an option to select the no of controls (may be one or two) and based on the selected number dynamically generate a Rad Editor and display on the control panel of the module at that time.Then the user fills the content in the editor and saves the same.

How do i accomplish this . Can you provide some source for dynamically generating the controls on the control panel of the module.

You should create a view. In the template of this view you need to add several LinklButtons. Each Linkbutton should have a CommandName. When pressed the page will make a post back and then a new control will be generated. Then save the control properties. The control should be added to the Controls collection so that you should also save its properties to the databse.

Tools

Sitefinity Professional Services

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.