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
Shiva-KumarAsked:
Who is Participating?
 
srikanthreddyn143Connect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.