ASP.net objects

Associate
Joined
11 Sep 2005
Posts
1,883
Location
Southport
Hi,

I have a very simple web application which consists of one main page and a background C# class containing the logic code. At the moment I am instantiating this object on the page's 'Page_Load' method (thus getting a new object each time the page is refreshed). This doesn't strike me as a particularly good or efficient way to do it.

Would it be better to keep this object stored in a session? Or simply copy the code out of it into the page class? Is there a better way? Or is it ok as it is? :)

Thanks
David
 
Not 100% sure I follow you, but,

You can store the object in a session or viewstate and determining if it's already been created by having the IsPostBack clause when the page loads.
 
Depends on the object, how its used and your website, for example...
Object is small, takes ages to created (complex db query) and you have loads of visitors - put it in the session.
Object is big, quick to create and you have loads of visitors - create it every time.
Object is big but is identical for each user - put it in the cache.

Remember if the object is created in the background code class or the page code class, it is created each and every time the page is viewed. ASP.Net pages are still stateless.
 
Back
Top Bottom