Hi, Here's my situation. I have a web control I call CommandBar that renders as a table containing a collection of CommandButton objects which are also WebControls, that it render within TableCells. I basically wanted the user to be able to dyanamically add
1..N CommandButton controls to the CommandBar through code behind. I'm not sure how I should implement the code to do this. 1. Should I simply expose and Add() method and add each CommandBar to the CommandBar.Controls collection? The client code-behind would
look something like.
2. Or, should I implement a CommandButtonCollection, populate it with CommandButton objects) and add that to the CommandBar? Code would look like...
CommandBar cmdBar = new CommandBar();
CommandButtonCollection buttons = new CommandBarCollection();
buttons.Add(new CommandButton("Ok"));
buttons.Add(new CommandButton("Cancel"));
buttons.Add(new CommandButton("Help"));
cmdBar.Items = buttons;
this.Controls.Add(cmdBar);
I've looked at some great examples on how to serialize Custom Types into a collection class using IStateManager on the items within the collection and the collection itself, yet it seems like I should be able to use the default ViewState
implementation for the CommandButton objects since it inherits from WebControl. But what about the CommandBarCollection? Is there a recommended way of implementing a WebControl that maintains a a custom typed collection of other web controls? Thanks for any
help anyone can provide.
jbucci
Member
35 Points
7 Posts
Using IStateManager for web control collections
Aug 06, 2003 01:27 PM|LINK
CommandBar cmdBar = new CommandBar(); cmdBar.Add(new CommandButton("Ok")); cmdBar.Add(new CommandButton("Cancel")); cmdBar.Add(new CommandButton("Help")); this.Controls.Add(cmdBar);2. Or, should I implement a CommandButtonCollection, populate it with CommandButton objects) and add that to the CommandBar? Code would look like...CommandBar cmdBar = new CommandBar(); CommandButtonCollection buttons = new CommandBarCollection(); buttons.Add(new CommandButton("Ok")); buttons.Add(new CommandButton("Cancel")); buttons.Add(new CommandButton("Help")); cmdBar.Items = buttons; this.Controls.Add(cmdBar);I've looked at some great examples on how to serialize Custom Types into a collection class using IStateManager on the items within the collection and the collection itself, yet it seems like I should be able to use the default ViewState implementation for the CommandButton objects since it inherits from WebControl. But what about the CommandBarCollection? Is there a recommended way of implementing a WebControl that maintains a a custom typed collection of other web controls? Thanks for any help anyone can provide.