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. How to modify Application level variable

How to modify Application level variable

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
9 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.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    I read some [semi] constant values from a file at application start -- File: global.asax.cs -- protected void Application_Start(Object sender, EventArgs e) { Application.Set(Name1, value1); } static public string Name1 { get { return "NAME1"; } } Later, when I need to access the value1, I can do something like: literal1.Text = Application[VSDonation.Global.Name1].ToString(); This is all working properly. However, I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work. Any pointers or ideas? Thanks. --G

    G G G 3 Replies Last reply
    0
    • G Glenn E Lanier II

      I read some [semi] constant values from a file at application start -- File: global.asax.cs -- protected void Application_Start(Object sender, EventArgs e) { Application.Set(Name1, value1); } static public string Name1 { get { return "NAME1"; } } Later, when I need to access the value1, I can do something like: literal1.Text = Application[VSDonation.Global.Name1].ToString(); This is all working properly. However, I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work. Any pointers or ideas? Thanks. --G

      G Offline
      G Offline
      Grapes R Fun
      wrote on last edited by
      #2

      just an idea... can you take in the value and store it in a non-static variable, then store that in another application variable? You are dealing with a static variable after all.

      Nila

      G 1 Reply Last reply
      0
      • G Glenn E Lanier II

        I read some [semi] constant values from a file at application start -- File: global.asax.cs -- protected void Application_Start(Object sender, EventArgs e) { Application.Set(Name1, value1); } static public string Name1 { get { return "NAME1"; } } Later, when I need to access the value1, I can do something like: literal1.Text = Application[VSDonation.Global.Name1].ToString(); This is all working properly. However, I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work. Any pointers or ideas? Thanks. --G

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

        Glenn E. Lanier II wrote:

        I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work.

        What kind of trouble? There should be no problem at all to modify the value. The code is exaclty as when you initally set the value.

        --- b { font-weight: normal; }

        G 1 Reply Last reply
        0
        • G Guffa

          Glenn E. Lanier II wrote:

          I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work.

          What kind of trouble? There should be no problem at all to modify the value. The code is exaclty as when you initally set the value.

          --- b { font-weight: normal; }

          G Offline
          G Offline
          Glenn E Lanier II
          wrote on last edited by
          #4

          If I create a class to write the value (so it can be used once when the application starts up and again when the administrator changes this value), I get: The type or namespace name 'Application' could not be found (are you missing a using directive or an assembly reference?) in reference to Application.Set(VSDonation.Global.Name1, sValue);

          G 1 Reply Last reply
          0
          • G Grapes R Fun

            just an idea... can you take in the value and store it in a non-static variable, then store that in another application variable? You are dealing with a static variable after all.

            Nila

            G Offline
            G Offline
            Glenn E Lanier II
            wrote on last edited by
            #5

            My problem is modifying/accessing the Application variable from anything other than the Global class.

            1 Reply Last reply
            0
            • G Glenn E Lanier II

              I read some [semi] constant values from a file at application start -- File: global.asax.cs -- protected void Application_Start(Object sender, EventArgs e) { Application.Set(Name1, value1); } static public string Name1 { get { return "NAME1"; } } Later, when I need to access the value1, I can do something like: literal1.Text = Application[VSDonation.Global.Name1].ToString(); This is all working properly. However, I need to modify the value stored as Application["NAME1"] from an administrative page. I'm having much trouble getting this work. Any pointers or ideas? Thanks. --G

              G Offline
              G Offline
              Glenn E Lanier II
              wrote on last edited by
              #6

              D'oh! My class that was trying to access the Application object was not derived from System.Web.UI.Page. Once I added that to the declaration, I can access the Application space. Thanks. Sorry. --G

              G 1 Reply Last reply
              0
              • G Glenn E Lanier II

                If I create a class to write the value (so it can be used once when the application starts up and again when the administrator changes this value), I get: The type or namespace name 'Application' could not be found (are you missing a using directive or an assembly reference?) in reference to Application.Set(VSDonation.Global.Name1, sValue);

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

                Use HttpContext.Current.Application to reference the application object.

                --- b { font-weight: normal; }

                1 Reply Last reply
                0
                • G Glenn E Lanier II

                  D'oh! My class that was trying to access the Application object was not derived from System.Web.UI.Page. Once I added that to the declaration, I can access the Application space. Thanks. Sorry. --G

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

                  That's not really a good way to do it, as your class is not a page. Use HttpContext.Current.Application to access the application object.

                  --- b { font-weight: normal; }

                  G 1 Reply Last reply
                  0
                  • G Guffa

                    That's not really a good way to do it, as your class is not a page. Use HttpContext.Current.Application to access the application object.

                    --- b { font-weight: normal; }

                    G Offline
                    G Offline
                    Glenn E Lanier II
                    wrote on last edited by
                    #9

                    Thanks. I've put that in place and it appears to do the trick in a more correct manner. --G

                    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