ASP.net VB.net set up a static global variable

Posted on 2012-08-14
Medium Priority
Last Modified: 2012-08-14

In ASP.net, what VB.net code do I use to set up and use a static global variable.
I want to apply a string value to it that can be used all over the project
Question by:Murray Brown
LVL 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 668 total points
ID: 38293537
I usually put something like that in the web.config so it can be configured later.


   <key ="MyKey" value = "MyValue" />

in code:

dim mystring as string = ConfigurationManager.AppSettings("MyKey")

More info:

Expert Comment

ID: 38293557
Try doing a little more digging before asking here. Found this example that seems to be the solution to your problem rather quickly.

LVL 83

Assisted Solution

CodeCruiser earned 664 total points
ID: 38293563
You can also use session. Add something to session

Session("MyVar") = MyVal

and you can access it anywhere else.
LVL 20

Accepted Solution

informaniac earned 668 total points
ID: 38293592
Declare a static property in your application.

public class Class1
        public static int MyProperty { get; set; }

// Inside the global.asax file Application_Start event initialize it's value
protected void Application_Start(object sender, EventArgs e)
Class1.MyProperty = 1;    

Now you can access this property anywhere from the application.

Author Closing Comment

by:Murray Brown
ID: 38293836
Thanks very much for the information

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question