Stripped WebControl without all font and color stuff

When developing your own web controls, it can sometimes be quite nice to get rid off all the junk that WebControl includes, such as Font, BackgroundColor etc.

If your doing simple HTML you can - instead of WebControl - inherit from:
System.Web.UI.HtmlControls.HtmlControl

This will however disable some of your possibilities with sub controls and such. You might want to go with System.Web.UI.Control which works for most cases.

All but one!

Because if you're writing a templated controll where you have the Container carry data just inhereting from Control won't do. You also need to tell .NET that it should parse it's children by adding the ParseChildren attribute before your class declaration. Like this:
using System;
using System.ComponentModel;
using System.Web.UI;

namespace MyProject.WebControls {
[ParseChildren(true), PersistChildren(false)]
public abstract class MyControl : Control, INamingContainer {
// Do your magic here :)
}
}

Related posts:

Comments

comments powered by Disqus