« More Control Over GridView Column | Main | New Blog »
October 18, 2006
Maintaining Collection Property State for Web Custom Controls
My blog has moved. Please go to: http://jstawski.com/archive/2006/10/18/Maintaining-Collection-Property-State-for-Web-Custom-Controls.aspx
I have dealt with this issue twice already, once being yesterday, and both times I found it very hard to find the solution. Therefore, i'm posting about it, not only for people to find the solution to their problem, but also for a reminder for me.
Anyway, developing Web Custom Controls is cool. It saves you time by using code reusability and the best part is Visual Studio makes it very easy to create one. Whenever you have properties on a control, by default they are shown on the property window of the control and whenever you set a property for the first time it adds an attribute to the tag element of that control. For example, if you set the visible property of a textbox to false at design time and then switch to the source, the textbox tag now looks like this:
<asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
(note the Visible attribute.) This is the way Visual Studio implements state for design time properties. The good news is you don't have to do anything special on your control for that to work. The not so good news is that this works for primitive types like Strings, Integer, Booleans or even Enums, but not so well with collections. In order for this to work, you have to set an attributes at the property level of the control:
PersistenceMode(PersistenceMode.InnerProperty)
Happy Programming!
02:54 PM | Permalink
Comments
The comments to this entry are closed.