?
Solved

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

Posted on 2012-08-14
5
Medium Priority
?
1,025 Views
Last Modified: 2012-08-14
Hi

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
0
Comment
Question by:Murray Brown
5 Comments
 
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.



eg:

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

in code:

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


More info:
http://msdn.microsoft.com/en-us/library/610xe886.aspx#Y85
0
 
LVL 1

Expert Comment

by:ktromp1
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.

http://stackoverflow.com/questions/4508606/global-variable-in-asp-net-website
0
 
LVL 83

Assisted Solution

by:CodeCruiser
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.
0
 
LVL 20

Accepted Solution

by:
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.
0
 

Author Closing Comment

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

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