By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,005 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,005 IT Pros & Developers. It's quick & easy.

Storing complete tree in session

P: n/a
I have the problem at the moment that I have to build
a page with all its dynamic buttons etc in order to get
postbacks on those buttons, then rebuild the control tree
in response to any possible postback.
What if I just stored the complete Control tree structure in
the session? Alternatively any better ways of doing this?
I have tried it on a simple page with 4 buttons and it
worked fine, e.g. something like this:
for(int i=0; i<4; i++)
Button button = new Button();
button.Text = "Keep Me: " + i.ToString();
button.Click += new EventHandler(button_Click);;
this.Session["everything"] =;
PlaceHolder oldOne = (PlaceHolder)(Session["everyth*ing"]);
ControlCollection coll = (ControlCollection)oldOne.Cont*rols;
this.Session["everything"] =;
Any views?

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
I would not do it like this this would result in your application not
being scaleable, use the session as little as possible.

Why not always create the control structure, regardless of if it is
post back?

Nov 19 '05 #2

P: n/a
If these controls need only be retained for postbacks to the page in
question, you can and probably should use ViewState to store the
controls. In this case, you would need to create the controls the
first time that the page is viewed. On the other hand, if you want to
retain the state of the controls across different pages, then Session
would make sense as a storage place. However, if you use session you
should check for the existence of the Session object when the page is
first viewed as in

private void Page_Load(object sender, System.EventArgs e)

//add the controls to the placeholder
//build the control tree and add the result to the placeholder

//other code here

Bill E.
Hollywood, F

Nov 19 '05 #3

P: n/a
Thanks for the replies. The question is about scalability, one problem
is that I really
have no way of judging the best way of doing this. It would be useful
to know whats done in practice.
Our web pages tend to be fairly big, as I can't measure memory size I
can't give a figure but some reach the 200k mark (as they do the work
of an application,
intranet rather than internet here.)

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.