Solved

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

Posted on 2009-05-06
3
272 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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