473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Storing complete tree in session

Hi
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:
if(!IsPostBack)
{
for(int i=0; i<4; i++)
{
Button button = new Button();
button.Text = "Keep Me: " + i.ToString();
button.Click += new EventHandler(button_Click);
this.ph.Controls.Add(button);
}
this.Session["everything"] = this.ph;
}
else
{
PlaceHolder oldOne = (PlaceHolder)(Session["everyth*ing"]);
ControlCollection coll = (ControlCollection)oldOne.Cont*rols;
while(coll.Count>0)
{
this.ph.Controls.Add(coll[0]);
}
this.Session["everything"] = this.ph;
}
Any views?
Ta
Shard

Nov 19 '05 #1
3 1191
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
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)
{

if(Session["everything"]!=null)
{
//add the controls to the placeholder
}
else
{
//build the control tree and add the result to the placeholder
}

//other code here
}

Bill E.
Hollywood, F

Nov 19 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
4
by: Max | last post by:
Hi guys, did some searching on the topic, but can't find much more then just basic info on binary trees. I need to write a binary tree implementation so that it is always complete. In other words...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
12
by: Alex D. | last post by:
is it possible? pros and cons?
7
by: Andrew Robinson | last post by:
I have a treeview control that I use as a menu & navigation control within a master page. The nodes for this control are loaded from a database which contains the text and url of each like and the...
8
by: rgparkins | last post by:
Hi I am creating a sign-up process on a web site much like that of a wizard form. I have browsed many sites to look for examples of how to store the entry data, so that the user can go back and...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.