0

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.

2
  • 1
    So, what is the real question? Commented Mar 21, 2015 at 7:10
  • question is how to load values at pageLoad, and keep it until the user redirects to another page. Commented Mar 21, 2015 at 9:12

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

what is the capacity of a viewstate ? how much data it can hold ?
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.
And the viewstate is stored inside the page html so the users will download it at each request
It's worth mentioning that MyClass musi be marked as Serializable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.