Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. keeping a class object alive beyond the life of the page

keeping a class object alive beyond the life of the page

Scheduled Pinned Locked Moved ASP.NET
winformsbusinesshelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DotNet_Newbie
    wrote on last edited by
    #1

    Hello All, I've a quick question. I'm developing a Multi tier web application with the business logic class separate from the ASPX pages. Now, what I'm having a problem with is: when a declare an instance of a business class in the code behind, this object gets destroyed and re-initialized every time the page gets posted back, what I'm looking for is a way to keep the object as is after its initial initialization so I don't loose the information contained in it. Thank you all in advance PS. The reason behind this, I have one main aspx page from which I load and unload several user controls, and before unloading any user control I gather its information and put in the business class.

    H M 2 Replies Last reply
    0
    • D DotNet_Newbie

      Hello All, I've a quick question. I'm developing a Multi tier web application with the business logic class separate from the ASPX pages. Now, what I'm having a problem with is: when a declare an instance of a business class in the code behind, this object gets destroyed and re-initialized every time the page gets posted back, what I'm looking for is a way to keep the object as is after its initial initialization so I don't loose the information contained in it. Thank you all in advance PS. The reason behind this, I have one main aspx page from which I load and unload several user controls, and before unloading any user control I gather its information and put in the business class.

      H Offline
      H Offline
      henningbenk
      wrote on last edited by
      #2

      Store the object in the session-Collection (you could do this in a function handling the PreRender-Event of the Page to ensure nothing is changed afterwards). During PageLoad get the object from session if form is posted back else initialize a new object.

      1 Reply Last reply
      0
      • D DotNet_Newbie

        Hello All, I've a quick question. I'm developing a Multi tier web application with the business logic class separate from the ASPX pages. Now, what I'm having a problem with is: when a declare an instance of a business class in the code behind, this object gets destroyed and re-initialized every time the page gets posted back, what I'm looking for is a way to keep the object as is after its initial initialization so I don't loose the information contained in it. Thank you all in advance PS. The reason behind this, I have one main aspx page from which I load and unload several user controls, and before unloading any user control I gather its information and put in the business class.

        M Offline
        M Offline
        Marcie Jones
        wrote on last edited by
        #3

        Hi DNWDN, Keep in mind that the web is stateless, so everything will have to be recreated on each HTTP request. What you need, rather than a way to persist your business class, is a way to persist the state of your data between requests. ASP.NET gives you several easy ways to manage state, the 2 simplest being:

        • ViewState: the data is encoded and stored at the client
        • Session state: the state data is held in memory on the server

        Now, if your business object is not large, you could actually store the object itself in the Session object for each user, but keep in mind that this approach does not scale well for a large number of users. Also, if your business object is serializable, you can store it into the ViewState. Hope that helps! Marcie http://www.codeproject.com

        D 1 Reply Last reply
        0
        • M Marcie Jones

          Hi DNWDN, Keep in mind that the web is stateless, so everything will have to be recreated on each HTTP request. What you need, rather than a way to persist your business class, is a way to persist the state of your data between requests. ASP.NET gives you several easy ways to manage state, the 2 simplest being:

          • ViewState: the data is encoded and stored at the client
          • Session state: the state data is held in memory on the server

          Now, if your business object is not large, you could actually store the object itself in the Session object for each user, but keep in mind that this approach does not scale well for a large number of users. Also, if your business object is serializable, you can store it into the ViewState. Hope that helps! Marcie http://www.codeproject.com

          D Offline
          D Offline
          DotNet_Newbie
          wrote on last edited by
          #4

          Hello, Thank you all very much for your fast response. - For keeping the object in the Session, this is out of the question because the business objects are large. (That is actually why I posted this question; I was looking for a way other than the Session) - For the ViewState: that is a really good suggestion, I know that for the web controls you can access and keep the state from the ViewState, but can you shed some light ( few hints or a quick example) on how to accomplish the same for my business objects, I would really appreciate it. Thanks again,

          M 1 Reply Last reply
          0
          • D DotNet_Newbie

            Hello, Thank you all very much for your fast response. - For keeping the object in the Session, this is out of the question because the business objects are large. (That is actually why I posted this question; I was looking for a way other than the Session) - For the ViewState: that is a really good suggestion, I know that for the web controls you can access and keep the state from the ViewState, but can you shed some light ( few hints or a quick example) on how to accomplish the same for my business objects, I would really appreciate it. Thanks again,

            M Offline
            M Offline
            Marcie Jones
            wrote on last edited by
            #5

            Paul Wilson has a great article all about ViewState: http://aspalliance.com/articleViewer.aspx?aId=135 Marcie http://www.codeproject.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups