Thursday, 28 January 2010

Creating Custom Controls - Back to basics

Sometimes you just need to stop and go back to the basics.

Yesterday I had some problems with nested controls in a custom control that was added to a Web part. The nested controls were losing their post back information, in the end it came down to a forgotten Interface, the INamingContainer. The INamingContainer is that small piece of magic that gives your composite control a new ID Namespace which uniquely identifies your control and all of its sub controls.
It is also worth noting that you need to add the child controls to the collection before setting their values for the TrackViewState() to be called, though you can do this manually.

Now I am going back to my old reference books to see what else I have let slip.