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. Question About Storing Objects in the Session Variable

Question About Storing Objects in the Session Variable

Scheduled Pinned Locked Moved ASP.NET
csharpquestionasp-net
6 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.
  • M Offline
    M Offline
    MarkMokris
    wrote on last edited by
    #1

    In an ASP.NET C# application, I have a class called "MyPanel" derived from Panel. MyPanel contains a Button with a Click event. The click event is handled in the MyPanel class. When I store any MyPanel objects in the Session variable and retrieve them on a postback, the Click events seem to disappear. When the user clicks a Button inside the MyPanel object, a postback happens, but the click events don't get executed. I have to "relink" the click handlers when I retrieve the MyPanel objects from Session. I am using InProc Session mode. I had though I could store even complex objects in the Session variable. But I lose the events in the objects. Is this explainable? Thanks, Mark

    C T 2 Replies Last reply
    0
    • M MarkMokris

      In an ASP.NET C# application, I have a class called "MyPanel" derived from Panel. MyPanel contains a Button with a Click event. The click event is handled in the MyPanel class. When I store any MyPanel objects in the Session variable and retrieve them on a postback, the Click events seem to disappear. When the user clicks a Button inside the MyPanel object, a postback happens, but the click events don't get executed. I have to "relink" the click handlers when I retrieve the MyPanel objects from Session. I am using InProc Session mode. I had though I could store even complex objects in the Session variable. But I lose the events in the objects. Is this explainable? Thanks, Mark

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why would you store them in a session ? How do the clicks 'disappear' ? A click event exists only for a postback. Once you store it in the session, it's just an object, it can't fire anything from the session and there's no event to store. The other issue is that your controls are regenerated on every postback. So, I doubt you'd have a reference to the same control, which means that any clicks that occured, would not occur in the controls you have in your session, as they are not all references to the same control.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • M MarkMokris

        In an ASP.NET C# application, I have a class called "MyPanel" derived from Panel. MyPanel contains a Button with a Click event. The click event is handled in the MyPanel class. When I store any MyPanel objects in the Session variable and retrieve them on a postback, the Click events seem to disappear. When the user clicks a Button inside the MyPanel object, a postback happens, but the click events don't get executed. I have to "relink" the click handlers when I retrieve the MyPanel objects from Session. I am using InProc Session mode. I had though I could store even complex objects in the Session variable. But I lose the events in the objects. Is this explainable? Thanks, Mark

        T Offline
        T Offline
        tagyurit
        wrote on last edited by
        #3

        A few questions: Is your mypanel object an actual object on the page, or are you initializing it at run-time? Are you wiring up the events by hand? Where are the events wired (what page event)? Why are you manually storing the object in the session? If you are re-linking the event handlers with each postback, I imagine that the click event itself is getting lost. 1) click event is generated - postback 2) event is re-linked to a handler (in page load?) 3) original click event should be handled, but the event handler was re-assigned in step 2...event is lost. I'm guessing that your object is not actually part of the page, but is created at run-time. I'm also guessing that this is why you are losing events. I would try to come up with a solution that involved the mypanel object as a 'static' object on the page. You will also avoid having to put the mypanel object in session state as a result. Best of luck. Rob tagyurit.com

        M 1 Reply Last reply
        0
        • T tagyurit

          A few questions: Is your mypanel object an actual object on the page, or are you initializing it at run-time? Are you wiring up the events by hand? Where are the events wired (what page event)? Why are you manually storing the object in the session? If you are re-linking the event handlers with each postback, I imagine that the click event itself is getting lost. 1) click event is generated - postback 2) event is re-linked to a handler (in page load?) 3) original click event should be handled, but the event handler was re-assigned in step 2...event is lost. I'm guessing that your object is not actually part of the page, but is created at run-time. I'm also guessing that this is why you are losing events. I would try to come up with a solution that involved the mypanel object as a 'static' object on the page. You will also avoid having to put the mypanel object in session state as a result. Best of luck. Rob tagyurit.com

          M Offline
          M Offline
          MarkMokris
          wrote on last edited by
          #4

          Thanks for the responses. To Rob...My MyPanel objects are objects on the page that are being dynamically created at runtime. Therefore at runtime, various user actions cause MyPanel objects to be created. When they are instantiated, the code links up click events for the buttons within. Since these dynamic MyPanel objects must persist between post-backs, my thought was to store them in an Array-List which is stored in the Session object. It works well, but I find the Click events no longer work after I pull them out of the Session object after the post-back. I must relink the Click events at that time. I am just wondering why. Thanks, Mark

          T 1 Reply Last reply
          0
          • M MarkMokris

            Thanks for the responses. To Rob...My MyPanel objects are objects on the page that are being dynamically created at runtime. Therefore at runtime, various user actions cause MyPanel objects to be created. When they are instantiated, the code links up click events for the buttons within. Since these dynamic MyPanel objects must persist between post-backs, my thought was to store them in an Array-List which is stored in the Session object. It works well, but I find the Click events no longer work after I pull them out of the Session object after the post-back. I must relink the Click events at that time. I am just wondering why. Thanks, Mark

            T Offline
            T Offline
            tagyurit
            wrote on last edited by
            #5

            In a sense, all event handlers are re-linked at postback. The difference is that objects that are static on your page have their handlers automatically linked by the framework. Since your control is dynamic, you must do it yourself. This link may be of interest to you:http://msdn.microsoft.com/en-us/library/ms178472.aspx[^] Is it possible to place the panels on the page as static objects and change their visibility property to hide them if you don't need them? Do you have variable set of panels preventing you from doing this? Give me a little more background - maybe there is a simpler solution. Rob http://tagyurit.com

            M 1 Reply Last reply
            0
            • T tagyurit

              In a sense, all event handlers are re-linked at postback. The difference is that objects that are static on your page have their handlers automatically linked by the framework. Since your control is dynamic, you must do it yourself. This link may be of interest to you:http://msdn.microsoft.com/en-us/library/ms178472.aspx[^] Is it possible to place the panels on the page as static objects and change their visibility property to hide them if you don't need them? Do you have variable set of panels preventing you from doing this? Give me a little more background - maybe there is a simpler solution. Rob http://tagyurit.com

              M Offline
              M Offline
              MarkMokris
              wrote on last edited by
              #6

              Thanks Rob. I didn't realize that events must be relinked at postback. Since these "MyPanels" are created dynamically, I guess the viewstate doesn't handle that for me and I will have to relink the events myself? That is how I am interpreting what you are saying. I am still learning about ASP.NET. I will investigate static objects. Maybe that is what I need to use. Thanks, Mark

              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