I'm having huge difficulties solving what should be a relatively trivial problem. The following is a gross simplification (obviously it's not that simple in reality) but it will serve its purpose:
I need to program a dynamically generated list, kind of like a shoutbox, that stores the messages in a Profile variable. I know, I know, the messages would be lost as soon as the session expires, but that'll be sufficient for this simplification.
Let's assume I have a Profile variable as such ...
Expand|Select|Wrap|Line Numbers
- List<string> messages = new List<string>();
Expand|Select|Wrap|Line Numbers
- class DynamicList : UserControl
- {
- protected void Page_Load( object sender, EventArgs e )
- {
- Label l;
- foreach( string s in Profile.messages )
- {
- l = new Label();
- l.Text = s + "<br />";
- Controls.Add( l );
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- class Shoutbox : UserControl
- {
- DynamicList list = new DynamicList();
- TextBox textbox = new TextBox();
- Button button = new Button();
- protected void Page_Load( object sender, EventArgs e )
- {
- button.Click += delegate
- {
- Profile.messages.Add( textbox.Text );
- };
- Controls.Add( list );
- Controls.Add( textbox );
- Controls.Add( button );
- }
- }
Rendering the dynamic list by overriding RenderControl is out of the question as there are several AJAX controls on that list and you can't "manually" render those.
Is there any solution to my problem?