For a while now I’ve been developing Web Magic, previously know as ePortal, a web-based ASP.Net designer that focus on easy-to-use features instead of hard-core developers. Although getting the initial version running was painful due to the lack of documentation I managed to get it implemented a long while ago. We’ve been developing more and more features in and out the designer, like Content Management, to make a real kick-ass product out of it.
The designer is a real ASP.Net designer as I do not use hacks to imitate Visual Studio. Its all build around the design-time interfaces Microsoft provides and you can add any ASP.Net control and expect it to work out-the-box. There is data binding, data source, external references and templated objects are in the works. This although cool was missing one thing at the present moment, ASP.Net 2.0 support.
Unlike what I expected Microsoft did some changes to the design-time support, most backward compatible, but really painful to debug. Here are some notes to save some time to anyone working on an ASP.Net designer 1.1 to 2.0 port… all right there shouldn’t be anyone doing that… but the Mono ASPNetEdit guys can find it useful.
FontNamesConverter
This converter no longer works if you do not provide a culture, although this is fairly understandable and easy to fix, I was expecting them to throw an informative exception instead of the NullException I was getting.
ExpandableObjectConverter and EmptyStringExpandableObjectConverter
One of the principal converters to anyone implementing .Net design-time (both for Windows Forms and ASP.Net). Loads of code around the properties and serialization of the documents are about this TypeConverter. The news in this chapter is the new EmptyStringExpandableObjectConverter that does nothing than serialize anything to an empty string. In fact this converter do not deserialize (ConvertFrom) from a string or any other object (Incorrect). I’ve found that they actually do convert from (but not into) an InstanceDescriptor object, something to be careful from now on.
The warning here is, use the is keyword to check for ExpandableTypeConverter.
IWebFormsReferenceManager and WebFormsReferenceManager
ASP.Net 2.0 introduced the abstract WebFormsReferenceManager class to extend some of the now obsolete IWebFormsReferenceManager. In fact, the IWebFormsReferenceManager was not required if you’re doing an ASP.Net 1.1 designer, but you would have to manage the Register directives and create the correct tags for the controls by yourself. What ASP.Net 1.1 ControlPersister.PersistControl did was to create a tag like “<System.Web.UI.WebControls.Label …>”, you needed to replace that by the correct “<asp:Label …” tag. Now, the reference manager is always required as you’ll get an exception when calling ControlPersister.PersistControl if your DesignerHost doesn’t provide it, and the tags come ready to “deployment”
The obsolete IWebFormsReferenceManager still works OK although the “upgrade” is pretty easy to implement.
TypeResolutionService
With the (I)WebFormsReferenceManager this service becomes obligatory. At least some of it. The GetAssembly method is the only required method, else, you’ll be debugging nasty Server Unknown Tag exceptions for the rest of your life. This one was by far the harder-to-track bug. The method argument is an AssemblyName, be sure you compare the Name and not the FullName against your referenced assemblies. In most common uses this method gets called with an AssemblyName argument retrieved from an Assembly name, but on control serialization the serializator only knows half the name (the bit you place on the ASP.Net Register directive) so the AssemblyName.FullName will be null.
The other methods are not used to serialize controls, although maybe they are in other situations or deserializing controls (something I do not do as my objects are saved in the db).
Well, there are more things about the design time support for ASP.Net 2.0 to be told. But I’ll leave that to the Part 2 of the article. I was hoping to write a few more articles like this and then create a site with all the details needed to create an ASP.Net designer, maybe someone wants to help with that?
Thanks for the info, especially on the converters. AspNetEdit
already uses a IWebFormReferenceManager and a semi-working TypeResolutionService, and has a custom ControlPersister that works properly for 1.1. I’m looking forward to the follow-up article
Is this code being published anywhere?
@Jess Sightler,
No,
sorry, its a closed-source commercial application. I would love to make the code available, but since I can’t… I can always try to contribute with knowledge and from time to time with code to the
Mono project.
I try to convert IWebFormsReferenceManager to
WebFormsReferenceManager, but the designer doesn?.´t show. Can you help me?
Hi, thanks for the post? Is your site a free theme or custom? I am intrigued by your site. Is it possible to include this article on one of my sites?, i will of course linkback to this page. Many Thanks
My site is a hybrid between raw html + wordpress and a custom theme. If you want to know more about the subject, use the search box on the blog pages and search for “custom wordpress”.
I would prefer you didn’t copy the entire contents of any post but yes, you can copy if you attribute the proper authorship, copyright notices and links to the originals.