locked
Making Object availble to Multiple Pages RRS feed

  • Question

  • User1492777471 posted

    I have created a object in ASP.net C# that is a collection (arraylist) of Arrest Warrant objects.  How do I make that object available to multiple pages?

    Saturday, February 12, 2011 11:54 PM

Answers

  • User1224194097 posted

    How do I make that object available to multiple pages?

    Save the arrayList in session

    Session["list"]=YourArrayList;

    and you can access that value from session in any other page

    ArrayList list=(ArrayList)Session["list"];

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 13, 2011 2:52 AM
  • User-1976290245 posted

    This link will be helpful

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 14, 2011 4:25 AM

All replies

  • User1224194097 posted

    How do I make that object available to multiple pages?

    Save the arrayList in session

    Session["list"]=YourArrayList;

    and you can access that value from session in any other page

    ArrayList list=(ArrayList)Session["list"];

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 13, 2011 2:52 AM
  • User1791120482 posted

    If you want to share some piece of information between pages, it is recommended to make use of Session object.  If it is between same page postback's, ViewState will do.. 

    Monday, February 14, 2011 2:41 AM
  • User-1976290245 posted

    This link will be helpful

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 14, 2011 4:25 AM
  • User-1976290245 posted

    Hi,

    If data is not so huge then you can use Session state management .Can you please clearify your requirement ?Means whether that object will be common to all users ? or whether it will be user specific ? How much data may it contain ?

    If you elaborate on these, someone may give you proper answer.


    Monday, February 14, 2011 6:26 AM
  • User-214697706 posted

    If the state of the List must be preserved through your application, and that List need to be reachable to all code inside you AppPool; then you should use either Static variable or HttpRuntime.

    the reason why i do not recommend Session or the evil brother Viewstate, is that neither are controlled by GC. Session is stored in memory as long as the session of the user is valid. your values inside Session will not be visible to other user. Viewstate however is bad bad bad, it clutters your html, eats bandwidth and has no real purpose. Some might argue that viewstate is used by most controls for postback, but that is not true. Most asp controls make use of Control state, and not viewstate. Control state is not something you can turn off.

    General rule I follow:

    1) if the data I need to store is for one user only, and never relevant to another, then store it session. But with one exception, even though a data is for one user alone and the data is large, I never use session; but Httpruntime.Cache. 

    2) If i need to persist short values between postback, i'll use Session or URL.

    3) Any other cases, most of the cases, I'll use HttpRuntime.Cache. 


    HttpRuntime.Cache wins, in my perspective, on all accounts. Number one reason is that you have 100% control of your data and for how long it is valid. You can even have dependencies with callback, for example: When this data is obsolete, perform this callback....


    Monday, February 14, 2011 6:40 AM
  • User-1976290245 posted

    2) If i need to persist short values between postback, i'll use Session or URL.

    I think in above situation ViewState can also be used ,since its data is small so it will not eat bandhwidth, and postback is on the same page.



    Monday, February 14, 2011 6:52 AM