Solved set up a static global variable

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

In, what 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:murbro
    LVL 39

    Assisted Solution

    by:Kyle Abrahams
    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:
    LVL 1

    Expert Comment

    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

    You can also use session. Add something to session

    Session("MyVar") = MyVal

    and you can access it anywhere else.
    LVL 20

    Accepted Solution

    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

    Thanks very much for the information

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    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 …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now