-----------------------------------------------------------
New Message on cochindotnet
-----------------------------------------------------------
From: DeepakG_MSFT
Message 2 in Discussion
Hi, Just checked - they are not. Only one instance of a static variable is mantained
for all instances of your page class. In fact, they behave quite like an Application
Variable.
To validate this you can do this - create a page with two buttons. Declare a static
variable. On click of one button increment the variable. On click of the second button
display the variable. Now fire up two instances of your page - you can increment from
the first page and retrieved the updated variable from the second:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
public static int x = 10;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public static void Increment()
{
x++;
}
public static int Retrieve()
{
return x;
}
private void Button1_Click(object sender, System.EventArgs e)
{
WebForm1.Increment();
}
private void Button2_Click(object sender, System.EventArgs e)
{
Label1.Text = WebForm1.Retrieve().ToString();
}
}
One small note - they should be used with caution - and for holding values that are
seldom or never updated. This is because if 2 or more pages touch the static variable
you can never be sure of what value it will have. Also check out this blog entry:
http://west-wind.com/weblog/posts/156.aspx
Cheers,
Deepak
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/cochindotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]