Simon Harvey wrote:
Hi everyone,
Can anyone tell me if I declare a global variable in my pages code behind,
is it persisted if the page does a post back, or do I need to add the object
to the session object in order to persist it.
Is the session the best mechnism for persisiting this object
Hi Simon!
The asp.net model doesn't automatically persist anything, and each time
the page is called (be it the first time or on postback) you have to
recreate everything.
The Session object is where you can get persistence on a per user basis.
Be aware that as the user count increase, so does the memory requirement
for using session objects. You might also want to think about how the
Session persistance is used in a web farm environment, because it will
mostly mean running the session from an external process or from a
remote sql database, which if used excensively can become a throughput
bottelneck.
You can also use the ViewState. In that case the data you persist is
serialized inside the web page, and the server doesn't pay the cost of
the persistence, and the web farm configuration is nearly automatic.
OTHA, the web page becomes bigger, the performance can decrease by the
deserialization cost, and the data transfer increases (which also
increase the responsiveness of the application).
All this to say that there's not one way of doing persistence, you need
to evaluate your needs. Try both solutions, and others if you want
(external sql you manage yourself, etc), and do some performance testing
to know where is the right thing. You might want to abstract this in a
Persistence class that would easily let you switch between different
solutions (mainly, using ViewState or Session and change that on the fly).
--
Sebastien Lambla [TheTechnologist]
The Geeky Lazy Bloggy
http://blog.thetechnologist.net