How to modify Application level variable
-
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 -
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. --Gjust 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
-
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. --GGlenn 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; }
-
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; }
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);
-
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
My problem is modifying/accessing the Application variable from anything other than the Global class.
-
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. --GD'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
-
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);
-
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
-
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; }
Thanks. I've put that in place and it appears to do the trick in a more correct manner. --G