Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Makieng my variable Global

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Husam - 09 Feb 2008 12:29 GMT
Hi EveryBody:

How can I make my variable as global or variable that declared in all my
entire project.

For Example in Desktop application you can add your variable to the Module
to make declared for the entire project.

How can I do So in my web Application?

any help will be appreciated

regard's

Husam
Phil Johnson - 09 Feb 2008 13:57 GMT
You can use the application session state for variables you want available
accross sessions (different users) and the session state for variables you
want available across a session (i.e. can be different values for different
users)

To use them, syntax is as follows:

To store a value in application state:

string GlobalVariable = "Some Value";
Application["GlobalVariable"] = GlobalVariable;

To retrieve a value from application state:

string RetrievedVariable = Convert.ToString(Application["GlobalVariable"]);

Session is the same syntax, but replace Application with Session.

Always remember that you can store different types in state, but they will
always be returned from state as an object, so you need to unbox them (i.e.
convert them to the type you put in there.

Also, its good practice to check the state variable is not null before
trying to retrieve it.

Hope that helps.
Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> Hi EveryBody:
>
[quoted text clipped - 11 lines]
>
> Husam
Peter Bromberg [C# MVP] - 09 Feb 2008 23:36 GMT
Besides what Phil mentioned, you can also declare public static fields in the
Global class (Global.asax).
So for instance if you have
public static DataSet GlobalDataSet
you can refer to it from anywhere in your app via:
DataSet myDataSet = Global.GlobalDataSet

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hi EveryBody:
>
[quoted text clipped - 11 lines]
>
> Husam
Jose A. Fernandez - 10 Feb 2008 18:09 GMT
Any class with static property is global for all session, and add
intellisense to Application variables.
Just create a class
Example:
  Public Class Util
        Public Shared Function AppPath() As String
             Return System.AppDomain.CurrentDomain.BaseDirectory()
        End Function

         Public Shared Property ExampleString() As String
       Get
           If HttpContext.Current.Application("ExampleString") IsNot
Nothing Then
               Return
HttpContext.Current.Application("ExampleString")
           Else
               Return String.Empty
           End If
       End Get
       Set(ByVal value As String)
           HttpContext.Current.Application("ExampleString") = value
       End Set
   End Property

End Class

______________________
Jose A. Fernandez
blog: http://geeks.ms/blogs/fernandezja

On 9 feb, 21:36, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote:
> Besides what Phil mentioned, you can also declare public static fields in the
> Global class (Global.asax).
[quoted text clipped - 23 lines]
>
> > Husam

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.