Solved

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

Posted on 2009-05-06
3
269 Views
Last Modified: 2012-05-06
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
Comment
Question by:Shiva-Kumar
  • 2
3 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24316698
You can have a seperae class file and gave global variables as public.
0
 

Author Comment

by:Shiva-Kumar
ID: 24316950
Could  you please show me an example
0
 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 250 total points
ID: 24317587
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

19 Experts available now in Live!

Get 1:1 Help Now