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