Originally Published: 2 October 2002
I've seen quite a few different templating schemes around since I started looking for them, but most had two flaws. One is the requirement to either use a
UserControl for every page or to load the controls into a template user control, which in both cases overcomplicates things and makes client-side scripting more obscure due to ASP.NET's unique Id system. The other is that most do not support view state properly, which is a consequence of changing the location of controls in the control tree after they're initially parsed into the tree.
Neither of these seemed acceptable to me, so I kept toying with the various schemes trying to arrive at what I thought to be the best of both worlds. The purpose of this article is to share that with you. The key to solving the view state problem lies in intercepting (overriding) ASP.NET's
AddParsedSubObject method, which adds the controls parsed from the ASPX page to the control tree.