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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Sharing ViewState data between controls

Sharing ViewState data between controls

Scheduled Pinned Locked Moved ASP.NET
helpquestion
3 Posts 2 Posters 2 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.
  • A Offline
    A Offline
    ake_krakbar
    wrote on last edited by
    #1

    I´m trying to share variables between two custom controls in ViewState. Control A sets a ViewState variable upon an eventhandler and after that Control B accesses the same ViewState variable. The problem is that when the second control tries to get the value from ViewState it is null. I have checked that the value is set before i try to fetch it so that´s not the problem. Is there some kind of issue here that I don´t know about? Using Session variables worked just fine, but it´s important that the data is being stored per page so I have to use ViewState. /Jonas

    G 1 Reply Last reply
    0
    • A ake_krakbar

      I´m trying to share variables between two custom controls in ViewState. Control A sets a ViewState variable upon an eventhandler and after that Control B accesses the same ViewState variable. The problem is that when the second control tries to get the value from ViewState it is null. I have checked that the value is set before i try to fetch it so that´s not the problem. Is there some kind of issue here that I don´t know about? Using Session variables worked just fine, but it´s important that the data is being stored per page so I have to use ViewState. /Jonas

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Each control has a ViewState collection, so if you want to access another controls ViewState, you have to use a reference to that actual control. If you put the value in the ViewState of the page, you should be able to reach it from any control. I haven't tried this though, so I don't know if it's even possible. If it is, you obviously can't use more than one set of those controls in each page, as they would collide otherwise. --- b { font-weight: normal; }

      A 1 Reply Last reply
      0
      • G Guffa

        Each control has a ViewState collection, so if you want to access another controls ViewState, you have to use a reference to that actual control. If you put the value in the ViewState of the page, you should be able to reach it from any control. I haven't tried this though, so I don't know if it's even possible. If it is, you obviously can't use more than one set of those controls in each page, as they would collide otherwise. --- b { font-weight: normal; }

        A Offline
        A Offline
        ake_krakbar
        wrote on last edited by
        #3

        Thanks for your reply. I tried to access the page view state, but haven´t managed to do it. There are no Page.ViewState och Context.ViewState properties. Maybe ViewState isn´t the best place to store pagewide global data that should be shared between controls...

        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