• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

asp.net global variable to be accessed by sub and remains unique for every instance

Hi,

I am new to asp.net.  how can i use a global variable which can be accessed by sub/function within the class and the variable stays unique for that session or instance.

Thanks
0
Shiva-Kumar
Asked:
Shiva-Kumar
  • 2
1 Solution
 
srikanthreddyn143Commented:
You can have a seperae class file and gave global variables as public.
0
 
Shiva-KumarAuthor Commented:
Could  you please show me an example
0
 
srikanthreddyn143Commented:
1.you can use sessions this way
http://www.devasp.net/net/articles/display/323.html

2. using global variables

http://dotnetperls.com/Content/Global-Variables-ASPNET.aspx

3. Or using classes
For Classes to be generally consumable across your site you would place them in the APP_Code folder.

 

The following simple class provides a global variable.

 

Imports Microsoft.VisualBasic

 

Public Class Sample

 

    Public Shared SomeText As String = "My Text"

 

End Class

 

Using it in a page

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

        Me.Title = Sample.SomeText

 

End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now