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. User control viewstate

User control viewstate

Scheduled Pinned Locked Moved ASP.NET
questionwinformssysadmin
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.
  • N Offline
    N Offline
    Not Active
    wrote on last edited by
    #1

    I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.

    C M 2 Replies Last reply
    0
    • N Not Active

      I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Mark Nischalke wrote: Using server controls instead of user controls is out of the question I'm confused. User Controls are processed on the server. Viewstate is also a server side technology. It has no meaning on the client side and is really just along for the ride (the server sends it to the client, the client doesn't use it but it is sent back to the server on the next page request) Mark Nischalke wrote: Ended up using cache What do you mean by this?


      Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      N 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Mark Nischalke wrote: Using server controls instead of user controls is out of the question I'm confused. User Controls are processed on the server. Viewstate is also a server side technology. It has no meaning on the client side and is really just along for the ride (the server sends it to the client, the client doesn't use it but it is sent back to the server on the next page request) Mark Nischalke wrote: Ended up using cache What do you mean by this?


        Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        In ascx1 I set ViewState["SomeValue"] = 1 ViewState["SomeValue"] is set properly and is usable elsewhere during the rendering of ascx1 In ascx2 I try to read ViewState["SomeValue"] but it is null I ended up using Cache.Insert on ascx1 with a very short time ( 5 sec ) and Cache.Remove on ascx2 when I'm done with it. A better implementation anyway since I don't need this value on the postback, only during processing.

        C 1 Reply Last reply
        0
        • N Not Active

          In ascx1 I set ViewState["SomeValue"] = 1 ViewState["SomeValue"] is set properly and is usable elsewhere during the rendering of ascx1 In ascx2 I try to read ViewState["SomeValue"] but it is null I ended up using Cache.Insert on ascx1 with a very short time ( 5 sec ) and Cache.Remove on ascx2 when I'm done with it. A better implementation anyway since I don't need this value on the postback, only during processing.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          There are a number of ways: You could stick it in the Session object. (Remembering to clean it out on the page_unload) Store it in the page class (although that might get a bit complex as you'd have to implement a storage mechanism on all pages that that these two controls sit on). I'm not sure if you can do this with user controls (or if it is feasible in your case), but if you can have a user control that contains these two controls, so a Master.ascx contains ascx1 and ascx2. The code for ascx1 seeks out ascx2 on the page controls and directly plants the value in ascx2.


          Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

          N 1 Reply Last reply
          0
          • C Colin Angus Mackay

            There are a number of ways: You could stick it in the Session object. (Remembering to clean it out on the page_unload) Store it in the page class (although that might get a bit complex as you'd have to implement a storage mechanism on all pages that that these two controls sit on). I'm not sure if you can do this with user controls (or if it is feasible in your case), but if you can have a user control that contains these two controls, so a Master.ascx contains ascx1 and ascx2. The code for ascx1 seeks out ascx2 on the page controls and directly plants the value in ascx2.


            Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            Colin Angus Mackay wrote: You could stick it in the Session object. I used Cache with sessionID as the key, but this may be cleaner.

            1 Reply Last reply
            0
            • N Not Active

              I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.

              M Offline
              M Offline
              Mike Hodnick
              wrote on last edited by
              #6

              What would happen if the second user control was on a page but the first one was not? You'd have a problem. I'd suggest designing the controls such that they don't depend on the existence of other specific controls on the page. Now in your app, that may not ever happen, but you never know... As a result, you'd need the second control to get the value differently. Some ideas have already been mentioned (e.g. use Session state). Or, the page the control is on could set the value too. Michael Hodnick www.kindohm.com blogs.kindohm.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