Hi,
Kindly go through the code below
	Now if i Click the first button, the value of "i" will be 5, and then whether I click on button2 or button3 then also it will be displayed as 5.
Now I redirect to another page., and from there I return to the above page.
And I click button2 or button3, I get the value as 5 (should not be it 0)
Now I close the application and run, And I click button2 or button3, I get the value as 5
Can anyone please explain it.
I mean does static behave like session. and secondly when i close the application and run again(build+run ) it shows the value 5.
Why is it so?
But if I initalise in page load event, it is showing properly. i.e. it does not show 5 when i click button 2 and button3
.Regards
cmrhema
					Kindly go through the code below
Code:
	public partial class _Default : System.Web.UI.Page 
{
    public static int i = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        i = 5;
        Response.Write(i.ToString());
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
      
        Response.Write(i.ToString());
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
       
        Response.Write(i.ToString());
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
       
        Response.Redirect("default3.aspx");
    }
}
Now I redirect to another page., and from there I return to the above page.
And I click button2 or button3, I get the value as 5 (should not be it 0)
Now I close the application and run, And I click button2 or button3, I get the value as 5
Can anyone please explain it.
I mean does static behave like session. and secondly when i close the application and run again(build+run ) it shows the value 5.
Why is it so?
But if I initalise in page load event, it is showing properly. i.e. it does not show 5 when i click button 2 and button3
.Regards
cmrhema
 
	
Comment