Hello,
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 ...
The user interface of my "web user control" is composed of the message list, a text box and a submit button. Each time the submit button is pressed, the message in the text box should be appended to the list.
A no-brainer: This is how I'm creating the dynamic list. The entire user control works as follows:
Again, very simple concept. The problem is that the list box "lags behind" one step because the event handlers are, oddly enough, called after the page is reloaded through Page_Load().
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?
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 ...
Code:
List<string> messages = new List<string>();
Code:
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 ); } } }
Code:
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?
Comment