-
February 15th, 2009, 01:11 PM
#1
hw to define global variable in c#
like i want 2 define a string variable wich hs value(text) as label1.text (for eg word=label1.text ) so i want 2 declare word as global variable which i able 2 use in any ASPX page..... plz help me.....
-
February 15th, 2009, 03:42 PM
#2
Re: hw to define global variable in c#
You can use Session State.
try to pick a book or read some tutorials about C# and asp.net.
-
February 15th, 2009, 04:10 PM
#3
Re: hw to define global variable in c#
create a public class, name it Globals, and use it....like so....
Code:
public class Globals
{
public static string SomeText = "some text";
}
protected void Page_Load()
{
label1.Text = Globals.SomeText;
}
-
February 16th, 2009, 03:10 AM
#4
Re: hw to define global variable in c#
Originally Posted by eclipsed4utoo
create a public class, name it Globals, and use it....like so....
Code:
public class Globals
{
public static string SomeText = "some text";
}
protected void Page_Load()
{
label1.Text = Globals.SomeText;
}
Note that using this technique, the variable is shared between all sessions. this can lead to concurrency issues. Different users will be reading/writing to the same variable.
-
February 16th, 2009, 08:30 AM
#5
Re: hw to define global variable in c#
if it's just static text(which it sounds like what he wants), it should be fine. Maybe create a property and only do the "get"?
Code:
public class Globals
{
private static string m_someText = "some text";
public static string SomeText
{
get { return Globals.m_someText; }
}
}
-
February 17th, 2009, 07:59 AM
#6
Re: hw to define global variable in c#
Originally Posted by hspc
Note that using this technique, the variable is shared between all sessions. this can lead to concurrency issues. Different users will be reading/writing to the same variable.
hi...
i understand create a global class bt problem is where to create that class
-
February 20th, 2009, 03:11 PM
#7
Re: hw to define global variable in c#
Originally Posted by madhuripokharkar
hi...
i understand create a global class bt problem is where to create that class
If it really should be global do i in the App_Code file.
If you need it only global in one specific session I would create it at the first time it is used and store it in the Session state using
Code:
string sometext;
Session.Add("MyVariable", sometext);
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|