Middle tier object persistence

Last post 09-13-2008 4:37 AM by Haissam. 2 replies.

Sort Posts:

  • Middle tier object persistence

    09-12-2008, 9:42 AM
    • Member
      34 point Member
    • ewgoforth
    • Member since 06-19-2007, 1:33 AM
    • Posts 81

    Hello,

    I have an .aspx page, on that page I have an .ascx web control, during the prerender event of the web control I'm instantiating a middle tier component that queries a database and builds a collection of objects.  I'm then using this collection to populate an asp:table on the web control. 

    FWIW, the middle tier component is a dll that's in the wwwroot\bin directory and has business logic regarding the state of the items in the collection, user permissions, etc.

    On the .ascx web control I also have a asp:button, when I click on this button, I'd like to be able to delete an object from this collection, have it delete from the database, etc.

     Problem is this middle tier component, even though it's declared outside the prerender event, is null inside the event handler for the asp:button.  Is there anyway to keep this middle tier component in memory as long as the page that contains the web control is open?

     I was hoping that this middle tier component would kind of have a "life of its own" independent of the data that was on my ASP.NET pages and components.

     -Eric

  • Re: Middle tier object persistence

    09-12-2008, 11:31 AM
    Answer
    • Participant
      1,582 point Participant
    • mohanbrij
    • Member since 08-07-2008, 8:40 AM
    • Bangalore, India
    • Posts 258

    To persist the data whether its a class object or variables, you need to use some persistance techniques like session, viewstate, etc.

    Or if your design permits then you can use static variables also. In short you can keep your Middle Tier object into Session or ViewState

    Please remember to click “Mark as Answer” on the post that helps you

    Best Regards
    Brij Mohan
    http://www.dotnetglobe.com
  • Re: Middle tier object persistence

    09-13-2008, 4:37 AM
    Answer
    • All-Star
      37,391 point All-Star
    • Haissam
    • Member since 10-05-2006, 2:25 AM
    • Beirut - Lebanon
    • Posts 5,632

    If this middle tier component is shared by all users ( same instance) then you can define it as static and it will be in the server's memory till the application restarts or ASPNET worker process recycles.

    If each user will need to have a different instance of the component then you would use Session State to save it. To access Session state from a dll or class use the below code

    System.Web.HttpContext.Current.Session[System.Web.HttpContext.Current.Session.SessionID] = MyDll;

    To retrieve it in the click event use

    MyComponentName myDLL = (MyComponentName) Session[Session.SessionID];

    Hope this helps,

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
Page 1 of 1 (3 items)