This project is read-only.

Extending the kit

Topics: Developer Forum
Dec 3, 2006 at 12:09 AM
First, great starter kit. There are not that many that are fully functional sites right out of the box.

Could you please post a little more detail (a "for dummies" type discussion would be nice) on the process to follow to extend the starter kit.


Dec 3, 2006 at 11:35 AM
Yes, you are right. We owe you more information about how to extend the kit and also how to modify/extend additional themes. We will provide them within the next couple of weeks.

However, there are two options for extending the kit:

1. Create additional modules in line with the architecture of those, which are already in the kit (News, Gallery, etc.). This is more complex and we will provide additional guidelines about how to do this.

2. The very easy way to add you own extension is to add ordinaryASP.NET 2.0 user controls (xyz.ascx). They don’t need to be connected to the MWPSK architecture at all. Simply insert these into the /EasyControls folder and add a ‘EasyControl’ compontent to your page. Here you can select the desired control to be shown on your page.


Dec 3, 2006 at 6:14 PM
Thanks for the response.
For now, I will take the "EasyControl" route. I look forward to the expanded documentation.

Again, thanks for posting this starter kit.
Dec 3, 2006 at 10:20 PM
Just in case anyone else is interested, if you use the "EasyControls" method, then the web user control that you write can be written in either VB.NET or C#. I've tested this quite a bit today and it works like a champ.

you can even import the MyWebPagesStarterKit namespaces in the code behind files for easy access to the existing code.

Jan 27, 2007 at 6:08 PM
Is there a place where we can share and discuss about controls we created? That would be nice.
Jan 28, 2007 at 7:55 PM

There is now a 'How to' about how to create EasyControls and additional sections.

Please let me know if you have extensions, which you would like to share with other people here. Please send me a message

Thanks a lot

Feb 6, 2007 at 6:59 AM
While waiting for more detailed instructions would you show us how to get started? I had a look at the Hello World example but it left me with more questions than it answered.

For example, I would like to create an EasyControl that allowed me to enter a URL for the page to be redirected after a delay. How and where do I store that URL and the delay time? How do I identify the page it should work on etc..

It would also be good if someone could post an example in VB. I know the project is in C# but I presume there's no reason we cannot use VB for controls? A couple of examples would be great!

Feb 6, 2007 at 10:53 AM

Uuups. This seems to be quite a special control. What I don't understand in your question is the 'How do I identify the page it should work on'? What do you mean by this 'page'?

Feb 6, 2007 at 12:47 PM
Hi Urs,

>>What I don't understand in your question is the 'How do I identify the page it should work on'? What do you mean by this 'page'?<<

In short: the ability to interface with MWPSK menus from an EasyControl.

For example I have a menu selection that goes to a forum. At the moment I have a forum.aspx that redirects to the forum, which is fine, but as I have a few of these I thought it would be neat to create an EasyControl. That way it becomes easy to maintain. With my current setup if I want to change the URL to the forum I have to edit forum.aspx. If I had an EasyControl I can edit it within the normal administration of the site.

I could develop code that would record this information in an XML file in the App_Data folder but to do that I would need to know the following:-

1. When saving the URL how do I identify the data with the Forum menu link? When I edit the Forum menu link at a later date I need recall the previously saved URL.

2. I can create an XML file but how do I know that it won't confilct with something the system already does? For example I may decide to call my XML file redirect.xml only to discover this is overwritten during some other system process.

3. And possibly you have a better way of storing and retrieving data which would take care of any problems that may be raised in 2.

I'm not sure that this would be a special control - the ability to have a menu option go to an external link, however it would cover the fundemental requirements of most controls (the ability to communicate with the MyWebPagesStarterKit interface).

If I can get this right I think I will be writing lots of controls, MWPSK is a fantastic product!

Feb 6, 2007 at 3:30 PM
Edited Feb 6, 2007 at 3:31 PM
Hi Martyn,

There are several possibilities how you could do this:

1. Do it your own way with an EasyControl

If you don't want to use the storage features of MWPSK, you can simply create your Usercontrol and implement whatever storage-mechanism you want. You can actually create your own xml-file in the App_Data folder. Nothing will be overwritten. With this approch, you cannot use the edit mode of MWPSK to configure your EasyControl tough (you would probably have to manipulate your data by hand). If you want to integrate your control completely into the MWPSK architecture, you must use the more complex method 2:

2. Do it the MWPSK way

Compared to a "simple" EasyControl, this is a more complicated approach. To make full use of all the MWPSK's infrastructure, you have to create your own section.
To learn how sections for MWPSK are built, you should have a look at the "HtmlContent" section. This is one of the easiest sections in MWPSK.
You can find the relevant files in the following locations:

-> App_Code/Sections/HtmlContent.cs
-> SectionControls/HtmlControl.ascx (with codebeside)

Those two files implement the logic of the HTML section. Let me point out a few things there:

This is the business class for the section. It has all the public properties and an inner class which is needed for serialization (saving content to App_Data).
First of all, notice, that the HtmlSection class is derived from Section<T>. The abstract Section<T> base class and its parent class Persistable<T> contain all the mechanics that a section must have. As you can see, the Section<T> class is a Generic. When deriving your new Section from it, you must give it the type of your inner (data-)class as type. Therefore, in HtmlSection, the Class declaration looks like this: public class HtmlContent : Section<HtmlContent.HtmlContentData>.
The only abstract method you have to implement is the Search() method. If you don't want your Section to be searchable, just return an empty List<SearchResult> object.
Your inner class must contain all the fields, you want to persist to the filesystem. These fields must be marked as public, so that the XmlSerializer can access and store them. To access the persisted properties in the outer class, you must use the _data field inherited from Section<T>.

This ascx file holds all the UI code of your section. Again, have a look at the HtmlControl section.
For controls with an admin view, there is usually a asp:multiview in the control. For this multiview, there are two asp:views one for the edit-mode, the other one for the readonly-mode (for all non-admins). Fill these two views with everything you need and create save and cancel buttons in the edit-view. Then switch to the codebeside file.
Your control must be derived from SectionControlBaseClass to work correctly. The HtmlContent.ascx.cs should be pretty self-explanatory. During runtime, MWPSK automatically creates an instance of your business class and assigns it to the property Section. Using this instance, you can then access all your properties and methods defined in the business class.

When you're done with implementing your own section, the last necessary step is, to give it a human readable name ;-) All the section's names are stored in the StringsRes.resx files in the App_GlobalResources directory. Open every language-file there and append a new entry. The name of your entry should be ctl_NAMEOFYOURCLASS_RssTitle where NAMEOFYOURCLASS is the class name of your business class (e.g. for the HtmlContent it's ctl_HtmlContent_RssTitle).
That's it. You can now log in as administrator and place your new section on any page you want.

I know this was a very brief overview on how to create your own sections. If you have some concrete questions feel free to ask them here in the forum. As already mentioned above, take the HtmlContent section for a good starting point.

Feb 6, 2007 at 4:28 PM
Hi Matthias,

I wasn't aware of what I needed until I read your post, now I see it was a road-map :)

Many thanks.

Kind Regards,
Feb 7, 2007 at 4:19 PM
By the way: here you can find a step-by-step guide and some sample code regarding the development of custom sections.