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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Declaring variable globally

Declaring variable globally

Scheduled Pinned Locked Moved ASP.NET
csharphelptutorial
12 Posts 4 Posters 1 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.
  • S srikantha_nagaraj

    Hi, How to declare variable globally so that i can use in entire my C# class. Please help me.

    A Offline
    A Offline
    Abhijit Jana
    wrote on last edited by
    #2

    Create Class of App_Code Folder. Access That Class variable from All over the Application :) For your Ref. Beginner's Guide to ASP.NET Application Folder [^]

    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

    S 1 Reply Last reply
    0
    • S srikantha_nagaraj

      Hi, How to declare variable globally so that i can use in entire my C# class. Please help me.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #3

      Are you talking about variables that every session can access ? If so then why not you use Application object. From your code : Applicatiion["yourvariablename"] = value; Now this value will be available globally to every session. Call this value using : object val = Application["yourvariablename"]; :rose::rose:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      N S 2 Replies Last reply
      0
      • A Abhishek Sur

        Are you talking about variables that every session can access ? If so then why not you use Application object. From your code : Applicatiion["yourvariablename"] = value; Now this value will be available globally to every session. Call this value using : object val = Application["yourvariablename"]; :rose::rose:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #4

        It was quite clear that the OP wasn't talking about session or application variables. Abhijit Jana already answered correctly about three hour before you. You should try reading the previous responses and going for quality rather than quantity in your responses.


        only two letters away from being an asset

        A 1 Reply Last reply
        0
        • A Abhijit Jana

          Create Class of App_Code Folder. Access That Class variable from All over the Application :) For your Ref. Beginner's Guide to ASP.NET Application Folder [^]

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          S Offline
          S Offline
          srikantha_nagaraj
          wrote on last edited by
          #5

          Hi, I am working ASP.Net 3.5. I am not able to create App_Code folder. There is no option for the App_Code folder.

          A 1 Reply Last reply
          0
          • A Abhishek Sur

            Are you talking about variables that every session can access ? If so then why not you use Application object. From your code : Applicatiion["yourvariablename"] = value; Now this value will be available globally to every session. Call this value using : object val = Application["yourvariablename"]; :rose::rose:

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like to.

            S Offline
            S Offline
            srikantha_nagaraj
            wrote on last edited by
            #6

            I am not able to create Application variable. I am unable to create appication or session variables. Please help me. I am facing some issues with that.

            A A 2 Replies Last reply
            0
            • S srikantha_nagaraj

              Hi, I am working ASP.Net 3.5. I am not able to create App_Code folder. There is no option for the App_Code folder.

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #7

              srikantha_nagaraj wrote:

              I am working ASP.Net 3.5. I am not able to create App_Code folder. There is no option for the App_Code folder

              Did you check the link that I have provided to you. On that article I have mention how to create the App_Code Folder. There is nothing to do with ASP.NET Version. On Solution Explorer > Right Click > Add ASP.NET Folder > App_Code. Thats All :) Again, Please check the link that I have provided to you on last post. Thanks !

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              S 1 Reply Last reply
              0
              • A Abhijit Jana

                srikantha_nagaraj wrote:

                I am working ASP.Net 3.5. I am not able to create App_Code folder. There is no option for the App_Code folder

                Did you check the link that I have provided to you. On that article I have mention how to create the App_Code Folder. There is nothing to do with ASP.NET Version. On Solution Explorer > Right Click > Add ASP.NET Folder > App_Code. Thats All :) Again, Please check the link that I have provided to you on last post. Thanks !

                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                S Offline
                S Offline
                srikantha_nagaraj
                wrote on last edited by
                #8

                Actually i am using web application to create my project not website as you have used in your article. But how can i do same in the web application? I have to have variable which will have counter of times i am inserting it to table.

                A 1 Reply Last reply
                0
                • S srikantha_nagaraj

                  I am not able to create Application variable. I am unable to create appication or session variables. Please help me. I am facing some issues with that.

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #9

                  It seems that you are not clear about what you are going to do. I will suggest you to Buy some beginners ASP.NET Books and start reading. This will help you to longer run. As you are confusing with Classes and Session/Application Variable. Thanks !

                  Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                  1 Reply Last reply
                  0
                  • S srikantha_nagaraj

                    Actually i am using web application to create my project not website as you have used in your article. But how can i do same in the web application? I have to have variable which will have counter of times i am inserting it to table.

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #10

                    srikantha_nagaraj wrote:

                    Actually i am using web application to create my project not website as you have used in your article.

                    You didn't mentioned it earlier. ;P Have a look, app_code folder in web application[^]

                    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                    1 Reply Last reply
                    0
                    • N Not Active

                      It was quite clear that the OP wasn't talking about session or application variables. Abhijit Jana already answered correctly about three hour before you. You should try reading the previous responses and going for quality rather than quantity in your responses.


                      only two letters away from being an asset

                      A Offline
                      A Offline
                      Abhishek Sur
                      wrote on last edited by
                      #11

                      I think this is wrong.. . Just see the response next to you, and see actually the user wanted my solution. We are here to give as many solutions as we can for each posts (so that the base gets enriched and others in future can get reference to it...) rather than to blame each others. If you see all my responses here in ASP.NET, you will see, I take lots of time to answer each post. I dont post just to increase my post counts. If you check all my responses, you can see my replies got less no of one liners... :-D

                      Abhishek Sur


                      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                      **Don't forget to click "Good Answer" if you like to.

                      1 Reply Last reply
                      0
                      • S srikantha_nagaraj

                        I am not able to create Application variable. I am unable to create appication or session variables. Please help me. I am facing some issues with that.

                        A Offline
                        A Offline
                        Abhishek Sur
                        wrote on last edited by
                        #12

                        You can use the following to create a variable name.

                        this.Request.Application["name"] = "This is my application";

                        To get the Name variable use

                        string s = this.Request.Application["name"].ToString();

                        If you are outside the page use

                        HttpContext.Current.Request.Application["name"]

                        instead. :rose::rose:

                        Abhishek Sur


                        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                        **Don't forget to click "Good Answer" if you like to.

                        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