I am building an ASP.NET Application which has 2 projects. One is a class library having BL Code. I want to create a public class instance variable from one of the classes in BL. This class instance variable is to avoid loading all the data on each request which makes my application to respond slow for each request. How to make the global class variable load data at page_Load, and keep it until the user redirects to another page.
-
1So, what is the real question?user2160375– user21603752015-03-21 07:10:29 +00:00Commented Mar 21, 2015 at 7:10
-
question is how to load values at pageLoad, and keep it until the user redirects to another page.Yesudass Moses– Yesudass Moses2015-03-21 09:12:25 +00:00Commented Mar 21, 2015 at 9:12
Add a comment
|
1 Answer
Create it in ViewState and wrap it in a property for easy of use. Something along the lines of:
public MyClass MyObj {
get {
if (ViewState["MyObj"] == null){
ViewState["MyObj"] = new MyClass();
}
return ViewState["MyObj"];
}
set {
ViewState["MyObj"] = value;
}
}
4 Comments
Yesudass Moses
what is the capacity of a viewstate ? how much data it can hold ?
Rajeesh Menoth
When u inserting large amount of data in view state.ViewState involves extra overload of serializing and deserializing the objects, so involves extra processing time.it's effect the performance.
Davide Lettieri
And the viewstate is stored inside the page html so the users will download it at each request