Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-05-06
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

704 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