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. shared variable

shared variable

Scheduled Pinned Locked Moved ASP.NET
question
14 Posts 5 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 nagendrathecoder

    Thats right, you'll face this problem. You can use Session variables in place of Shared. :)

    B Offline
    B Offline
    Blikkies
    wrote on last edited by
    #5

    Same problem with session, thats why i use shared.

    modified on Tuesday, October 6, 2009 4:10 AM

    N 1 Reply Last reply
    0
    • B Blikkies

      Same problem with session, thats why i use shared.

      modified on Tuesday, October 6, 2009 4:10 AM

      N Offline
      N Offline
      nagendrathecoder
      wrote on last edited by
      #6

      No Way, how are you using them? :^) Can you show your code?

      B 1 Reply Last reply
      0
      • N nagendrathecoder

        No Way, how are you using them? :^) Can you show your code?

        B Offline
        B Offline
        Blikkies
        wrote on last edited by
        #7

        shared shouldnt be referenced in both tabs, both tabs should have their own.

        N 1 Reply Last reply
        0
        • B Blikkies

          shared shouldnt be referenced in both tabs, both tabs should have their own.

          N Offline
          N Offline
          nagendrathecoder
          wrote on last edited by
          #8

          I don't think this is true. :doh: Shared variable is common. In my beginnings days, i also used Shared variable but then i got same problem. Then i used Session variables which solved my problem. Basic thing is, for what purpose you are using Shared or Session variables.

          B 1 Reply Last reply
          0
          • N nagendrathecoder

            I don't think this is true. :doh: Shared variable is common. In my beginnings days, i also used Shared variable but then i got same problem. Then i used Session variables which solved my problem. Basic thing is, for what purpose you are using Shared or Session variables.

            B Offline
            B Offline
            Blikkies
            wrote on last edited by
            #9

            I used shared variable to store User ID that I reference in different instances. What i understand is that two different tabs runs same class but all variables are initialized, in other words both tabs runs the sam class but variables are not the same.

            N 1 Reply Last reply
            0
            • B Blikkies

              I used shared variable to store User ID that I reference in different instances. What i understand is that two different tabs runs same class but all variables are initialized, in other words both tabs runs the sam class but variables are not the same.

              N Offline
              N Offline
              nagendrathecoder
              wrote on last edited by
              #10

              Blikkies wrote:

              two different tabs runs same class but all variables are initialized

              This is what i am telling you, opening a new tab will initialize all variables but not shared variable, shared variable will retain its previous value. I also used shared variable for storing user ids and i got stuck up. Try to use Session Variables, assign session variable after successful login, it won't definitely repeat on new tab. :)

              1 Reply Last reply
              0
              • B Blikkies

                Do anyone use shared variable in their ASP projects?

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

                A shared variable will be the same for all users of the website, but will be reset to the default value every time the web server gets reset. As a result, I can't imagine a valid use for one in a website. If I found I had a valid use for one, I would use it, but if I want to persist a value across all pages, I'd use a database, so it doesn't get reset by IIS.

                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.

                B 1 Reply Last reply
                0
                • C Christian Graus

                  A shared variable will be the same for all users of the website, but will be reset to the default value every time the web server gets reset. As a result, I can't imagine a valid use for one in a website. If I found I had a valid use for one, I would use it, but if I want to persist a value across all pages, I'd use a database, so it doesn't get reset by IIS.

                  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.

                  B Offline
                  B Offline
                  Blikkies
                  wrote on last edited by
                  #12

                  I used sharing variable in one of my sites backend, I have a grid that shows delegates with a button in each row that update that delegate details, when the user click on one of the buttons, i set the Sharing Variable equels to that Delegate ID that will be used to update that user, the problem that a faced is when i open two tabs with the same URL, they both reference the same variable that caused data to be override in database causing duplicates. In your previous reply, you said "A shared variable will be the same for all users of the website", does it mean that Shared Variables is used global like Application Variable?

                  C 1 Reply Last reply
                  0
                  • N nagendrathecoder

                    Thats right, you'll face this problem. You can use Session variables in place of Shared. :)

                    T Offline
                    T Offline
                    Thanigainathan S
                    wrote on last edited by
                    #13

                    Its common for the application. So whichever user changes the variable it gets changed. You can use session variable if needed. Thanks, Thani

                    India is Mythical and so we are

                    1 Reply Last reply
                    0
                    • B Blikkies

                      I used sharing variable in one of my sites backend, I have a grid that shows delegates with a button in each row that update that delegate details, when the user click on one of the buttons, i set the Sharing Variable equels to that Delegate ID that will be used to update that user, the problem that a faced is when i open two tabs with the same URL, they both reference the same variable that caused data to be override in database causing duplicates. In your previous reply, you said "A shared variable will be the same for all users of the website", does it mean that Shared Variables is used global like Application Variable?

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

                      Yes, that is exactly how a shared variable works, that's the point of it. Hence the name, shared. You need to store that value in viewstate, because it's only being used on one page, and yes, as everyone said, shared means all users will have the same value.

                      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
                      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