ParseChildren in Templated Controls

Well, I have been spending sometime learning about Templated controls at work. Hence I am slowly getting an understanding of common attributes that you would want to use on Templated controls. If your template control inherits from WebControl than you do not need to worry about setting ParseChildren to true because by default WebControls have ParseChildren set to true. However if your controls inherit from Control class, than in order to get Templates to work you need to set ParseChildren to true. When you set ParseChildren to true, asp.net parser maps the top level tags of the server control to properties on the server control. For e.g

<cc:KeyWordControl runat="server" id="test">
   <KeyWords>
     content goes here.
  </KeyWords>

[ParseChildren(true)]
public class KeyWordControl

{

public ITemplate KeyWords{get;set;}

}

When ParseChildren is set to true, KeyWords tag automatically gets mapped to KeyWords property on your server control. If the value is not set to true, than everything inside of it is considered as Literal control and does not get parsed.

No Comments